I am using the patchify library to create patches of a bigger .jpg image. I am using the following code, taken from this YT video: https://www.youtube.com/watch?v=7IL7LKSLb9I&ab_channel=DigitalSreeni
When the YT guy reads his images (12 tiff images) he gets the following size for the large_image_stack variable: (12, 768, 1024), i.e. 12 images each of those is 768x1024.
I have a single jpg image of 3000x4000 and the size I am getting for large_image_stack variable is (3000, 4000, 3). So then I run the code...
import numpy as np
from matplotlib import pyplot as plt
from patchify import patchify
import cv2
large_image_stack = cv2.imread("test.jpg")
for img in range(large_image_stack.shape[0]):
large_image = large_image_stack[img]
patches_img = patchify(large_image, (224,224), step=224)
for i in range(patches_img.shape[0]):
for j in range(patches_img.shape[1]):
single_patch_img = patches_img[i,j,:,:]
cv2.imwrite('patches/images/' + 'image_' + str(img)+ '_' + str(i)+str(j)+ '.jpg', single_patch_img)
But I am getting the following error:
ValueError: window_shape
is too large
Looking in the view_as_windows.py from the patchify library I see the following:
arr_shape = np.array(arr_in.shape)
window_shape = np.array(window_shape, dtype=arr_shape.dtype)
if ((arr_shape - window_shape) < 0).any():
raise ValueError("`window_shape` is too large")
And as I am quite new in these things I can't get this error solved.
Any help would be very appreciated!!