def resize_save(path, size):
path = os.path.join(os.getcwd(), path)
images_files = os.listdir(path)
el = (np.array([[0,1],[1,1]])).astype(np.float32)
for i, image in enumerate(images_files):
image_file = os.path.join(path,image)
try:
im = (ndimage.imread(image_file)).astype(np.float32)
np.putmask(im, im < 100, 0)
im = ndimage.binary_dilation(im, structure=el)
im = (misc.imresize(im, (size, size))).astype(np.uint8)
new_im = Image.fromarray(im)
new_im.save(image_file)
except Exception as e:
print('Could not read:', image_file, ':', e, '- it\'s ok, skipping.')
评论列表
文章目录