I am using patchify library to patch a big image:
img = cv2.imread("resized.jpg")patches_img = patchify(img, (224,224,3), step=224)print(patches_img.shape)
Then I save the patches:
for i in range(patches_img.shape[0]): for j in range(patches_img.shape[1]): single_patch_img = patches_img[i, j, 0, :, :, :] if not cv2.imwrite('patches/images/'+'image_'+'_'+ str(i)+str(j)+'.jpg', single_patch_img): raise Exception("Could not write the image")
Then, I want to make some modification on any of those patches, e.g. draw bounding boxes, so when I use unpatchify to merge patches together, the bounding boxes would be displayed on the reconstructed image.
After making the modifications, I run the following code to merge the patches back together:
reconstructed_image = unpatchify(patches_img, img.shape)cv2.imwrite("unpatched.jpg", reconstructed_image)
But the reconstructed image generated is the same as the original one, with no change visible.I assume this is because unpatchify reads the variable patches_img, which has still stored the original, unmodified patches.
I tried the following:
patches = 'patches/images/*.jpg'reconstructed_image = unpatchify(patches, img.shape)cv2.imwrite("unpatched.jpg", reconstructed_image)
But I am getting AttributeError: 'str' object has no attribute 'shape'
Thanks you!