Patchify in python:
When ever we used GAN or deep learning, we need small image size , it will be better to get god result. I have face this problem , when i was working with GAN , it give 400 patches in a single image, so i do it manually, which is too much time consuming . But a few week ago , i found this amazing method, patchify in python to solve this problem.
So basically patchify in python help to get patches according to your required size. There is a python library name as ‘patchify’ , it help to cropped large images into small patches according to your given size. you can install by using one line command.
pip install patchify
Then you can used this below code to patchify large images and save into to new file with new name separately. All these things are automatic , so it is really amazing
image = cv2.imread(“test.jpg”)
patches image = patchify(image, (224,224,3), step=224)
for i in range(patches image. Shape):
for j in range(patches image. Shape):
single_patch_image = patches image[i, j, 0, :, :, :]
if not cv2.imwrite(‘patches/images/’ + ‘image_’ + ‘_’+ str(i)+str(j)+’.jpg’, single_patch_image):
raise Exception(“Could not write the image”)
Read more: patchify