Skip to content

Instantly share code, notes, and snippets.

@cacheninetynine
Created October 30, 2024 15:46
Show Gist options
  • Save cacheninetynine/1325e1426ff9b13e495381fe3ef4ae76 to your computer and use it in GitHub Desktop.
Save cacheninetynine/1325e1426ff9b13e495381fe3ef4ae76 to your computer and use it in GitHub Desktop.
python bitplanes thing or something idk
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