How to extract patches from an image in pytorch/tensorflow into 4 equal parts?
I am using a 16x16 colour image; I wrote small code for that but could not perform it precisely.
import numpy as np
from patchify import patchify
image = cv2.imread('subbu_i.jpg')
print(image.shape)
patches = patchify(image, (4,4), step=1) 
print(patches.shape)

Any ideas?

For Tensorflow, try tf.image.extract_patches
import tensorflow as tf
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np

image = Image.open('/content/image.png')
plt.imshow(image)

image = tf.expand_dims(np.array(image), 0)
image = tf.expand_dims(np.array(image), -1)
patches = tf.image.extract_patches(images=image,
                        sizes=[1, 4, 4, 1],
                        strides=[1, 4, 4, 1],
                        rates=[1, 1, 1, 1],
                        padding='VALID')

axes=[]
fig=plt.figure()

for i in range(4):
    axes.append( fig.add_subplot(2, 2, i + 1) )
    subplot_title=(&quot;Patch &quot;+str(i + 1))
    axes[-1].set_title(subplot_title)  
    patch = tf.reshape(patches[0, i, i], (4, 4))
    plt.imshow(patch)
fig.tight_layout()    
plt.show()



