dovahcrow/patchify.py

images of same shape do not always return same number of patches

aegonwolf opened this issue · 0 comments

I'm running the latest version of patchify 0.2.3.
I'm creating patches for a dataset with tifs and masks each of which have the same shape (I run a check).

def make_patches(path, channels):
  flag = 1 if channels == 3 else 0
  image = cv2.imread(path, flag) 
  SIZE_X = (image.shape[1]//patch_size)*patch_size 
  SIZE_Y = (image.shape[0]//patch_size)*patch_size
  image = image[:SIZE_Y, :SIZE_X]       

  #Extract patches from each image
  if channels == 3:
    patches_img = patchify(image, (patch_size, patch_size, channels), step=patch_size) 
    patches_img = np.reshape(patches_img, (-1, patch_size, patch_size, channels))
  else:
    patches_img = patchify(image, (patch_size, patch_size), step=patch_size)  
    patches_img = np.reshape(patches_img, (-1, patch_size, patch_size, 1))
  return patches_img

the pngs are single channel.

Why would patchify create a different number of patches for images of the same dimensions (width, height)?