MATLAB: Dividing image into 2×2 blocks and calculating SSIM for each block.

Image Processing Toolboxssim

Hey,
I'm trying to compare two images. I need to break each image into 2×2 blocks and come compare each block using the SSIM function Thanks

Best Answer

Assuming that the size of the image is a multiple of the window size (which as Image Analyst pointed out probably needs to be bigger than 2x2):
%img1, img2: images to compare
blocksize = [2 2]; %should probably be [8 8]
rowdist = ones(1, size(img1, 1)/blocksize(1)) * blocksize(1);
coldist = ones(1, size(img1, 2)/blocksize(2)) * blocksize(2);
ssimblocks = cellfun(@ssim, mat2cell(img1, rowdist, coldist, size(img1, 3)), ...
mat2cell(img2, rowdist, coldist, size(img2, 3)))