def crop_images(path_images, path_output, dimensions, centre=True):
"""
Batch crop images from top left hand corner to dimensions specified. Skips
images where dimensions are incompatible.
"""
print 'cropping images...'
for i, filename in enumerate(os.listdir(path_images)):
try:
image = io.imread('{}{}'.format(path_images, filename))
cropped = crop_image(image, dimensions, centre=centre)
io.imsave(
fname='{}{}'.format(path_output, filename),
arr=cropped
)
print '{}: {}'.format(i, filename)
except IndexError:
print '{}: {} failed - dimensions incompatible'.format(i, filename)
print 'all images cropped and saved.'
评论列表
文章目录