Using Python, I have to:
Test_Image
and Reference_image
into 5x5 blocks,
I have write this code two automatically split image into n rows and m columns. m and n are arguments and it is easily modifiable. After that it is easy compute histogram for each block which are also saving into the folder named patches.
# Image path, number of rows
# and number of columns
# should be provided as an arguments
import cv2
import sys
import os
if not os.path.exists('patches'):
os.makedirs('patches')
nRows = int(sys.argv[2])
# Number of columns
mCols = int(sys.argv[3])
# Reading image
img = cv2.imread(sys.argv[1])
#print img
#cv2.imshow('image',img)
# Dimensions of the image
sizeX = img.shape[1]
sizeY = img.shape[0]
print(img.shape)
for i in range(0,nRows):
for j in range(0, mCols):
roi = img[i*sizeY/nRows:i*sizeY/nRows + sizeY/nRows ,j*sizeX/mCols:j*sizeX/mCols + sizeX/mCols]
cv2.imshow('rois'+str(i)+str(j), roi)
cv2.imwrite('patches/patch_'+str(i)+str(j)+".jpg", roi)
cv2.waitKey()