Created
October 30, 2024 15:46
-
-
Save cacheninetynine/1325e1426ff9b13e495381fe3ef4ae76 to your computer and use it in GitHub Desktop.
python bitplanes thing or something idk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
def make_bitplanes(path): | |
img = Image.open(path) | |
bitplanes = [[],[],[],[],[],[],[],[]] | |
for color in img.convert("L").getdata(): | |
bincolor = bin(color)[2:] | |
bincolor = ("0"*(8 - len(bincolor)))+bincolor | |
for i, v in enumerate(bincolor): | |
bitplanes[i].append(int(v)) | |
for i, plane in enumerate(bitplanes): | |
bpimage = Image.new("1",img.size) | |
bpimage.putdata(plane) | |
bpimage.save(f"bitplane_{i}.png") | |
if __name__ == "__main__": | |
make_bitplanes("parrot.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment