Home > Mobile >  Dividing images into patches
Dividing images into patches

Time:02-03

i would like to practise with library of patchify in order to learn how to divide image into several patches, for this , i found following site : ocean image

dimension of this image is 612 X 408, so on the based of site, i have applied code and got the following error :

raise ValueError("window_shape is incompatible with arr_in.shape") ValueError: window_shape is incompatible with arr_in.shape

the code is given here :

`import numpy as np
from patchify import patchify
from PIL import Image
import cv2
#ocean =Image.open("ocean.jpg") #612 X 408
ocean =cv2.imread("ocean.jpg")
print(ocean.size)
ocean = np.asarray(ocean)
patches =patchify(ocean,(306,204),2)
print(patches.shape)
for i in range(patches.shape[0]):
    for j in range(patches.shape[1]):
        patch = patches[i, j]
        patch = Image.fromarray(patch)
        num = i * patches.shape[1]   j
        patch.save(f"patch_{num}.jpg")`

so my question is how can determine window shape? i used (306,204) because it is simple half of the original image's shape, is there any rule of choosing window shape?when i searched about this problem, i found following solution

enter image description here enter image description here

enter image description here enter image description here

  • Related