Skip to content

Instantly share code, notes, and snippets.

@islem-esi
Last active May 24, 2023 19:37
Show Gist options
  • Save islem-esi/5b3f3d585137d302b63a69b468f10f25 to your computer and use it in GitHub Desktop.
Save islem-esi/5b3f3d585137d302b63a69b468f10f25 to your computer and use it in GitHub Desktop.
from os import listdir
from PIL import Image
import os.path
import numpy as np
path = 'path/to/folder/containing/exe/files'
h = 256 #height of image
w = 256 #width of image
#be careful with using this function, it will consume memory, access to disk and time
images = []
for f in listdir(path_new):
with open(os.path.join(path_new, f), 'rb') as img_set:
img_arr = img_set.read(h*w)
while img_arr:
if len(img_arr) == h*w and img_arr not in images:
images.append(img_arr)
img_arr = img_set.read(h*w)
#And you can save them into png files
count = 0
for img in images:
png = Image.fromarray(np.reshape(list(img), (h,w)).astype('float32'), mode='L')
png.save('image_l%d.png'%count)
count += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment