Image comparison using MATLAB I want to compare a bunch of depth images coming from Kinect and eliminate the similar ones. Those images present posture of a single user sitting on the chair (depicted in).



My idea is to create a function which will return the difference in range [0,1] between two postures. This means, I want to compare only a posture for given two images (a grey region). For example, if I pass images to my function, the result will be 0 (because postures are the same, but not at the same position on the picture). 

Hence, I need to modify the following code (and find something to replace "correlation"):

a = imread('image_user_depth_000041.jpg');  %first img
b = imread('image_user_depth_000042.jpg');  %second img
a = RGB2IND(a,16);
b = RGB2IND(b,16);

c = corr2(a,b);           %finding the correlation 
if c==1
 disp('The images are same') % display
else
 disp('the images are not same')
end;


Do you have any suggestions? 
My regards and thanks!
You can borrow from techniques used by the image stitching community, where they have to deal with registering translated and rotated images. Your mistake was that you calculated the correlation before finding the optimal translation. The Wikipedia article should give you enough information to help yourself.

Mathematica Example

First, I split the picture above into frame1.png and frame2.png. Then I shifted the second one to align with the first, and trimmed both to retain their intersection. Finally, I compute the correlation coefficient by flattening the matrix into a vector.

img1 = ColorConvert[Import["frame1.png"], "Grayscale"]
img2 = ColorConvert[Import["frame2.png"], "Grayscale"]
im2t = ImageAlign[img1, img2, "Transformation" -&gt; "Translation"]
imgtr = FindGeometricTransform[img1, img2, "Transformation" -&gt; "Translation"]
{trx, try} = Part[TransformationMatrix@Last@imgtr, {1, 2}, 3]
{trim1, trim2} = ImageTake[#, {1, Floor@try}, {1, Floor@trx}] &amp; /@ {img1, im2t}
{cimg1, cimg2} = Flatten@First@ImageData[#, "Interleaving" -&gt; False] &amp; /@ {trim1, trim2};
Correlation[cimg1, cimg2]


The result I got was 0.967834, indicating a close match. If necessary I would have considered scaling and rotation to better align the images but it was not necessary here.

Here is a MATLAB example.