Skip to content

Instantly share code, notes, and snippets.

@aleozlx
Created August 4, 2021 02:39
Show Gist options
  • Save aleozlx/5e96f96d6e5b942737a498eb7e44604f to your computer and use it in GitHub Desktop.
Save aleozlx/5e96f96d6e5b942737a498eb7e44604f to your computer and use it in GitHub Desktop.
from pathlib import Path
from PIL import Image, ImageOps
def write_bin():
base_dir = Path(__file__).parent
a = 390
im = ImageOps.grayscale(Image.open(str(base_dir / "buildings_original.jpg"))).resize((a, a))
data = bytearray([im.getpixel((x, y)) for x in range(a) for y in range(a)])
with open(str(base_dir / "buildings_original.bin"), 'wb') as f:
f.write(data)
def write_jpg():
base_dir = Path(__file__).parent
a = 390
for c_out in range(32):
with open(str(base_dir / ("buildings_filter.%02d.bin" % c_out)), 'rb') as f:
data = bytearray(f.read())
print(len(data))
im = Image.new('L', (a, a), 0)
[im.putpixel((x, y), data[y*a+x]) for x in range(a) for y in range(a)]
im.save(str(base_dir / ("buildings_filter.%02d.jpg" % c_out)))
if __name__ == "__main__":
# write_bin()
write_jpg()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment