# Find the higher degree of similarity between images and report the points in common and the differences

I am trying to analyse due different images and find their similarities. In order to do this, I need to consider the coordinates of the pixels in both images, then select the points in common, i.e. those points with small distance or higher degree of similarity. However, I have some problems to select only those points in common for each of the two images using Mathematica.

EDIT:

img1 = Image[
Import@FileNameJoin[{NotebookDirectory[], "simpson1.jpg"}]];
pixels1 = ImageData[img1]

img2 = Image[
Import@FileNameJoin[{NotebookDirectory[], "simpson2.jpg"}]];
pixels2 = ImageData[img2]

grouping = GroupBy[pixels1, pixels1 - Nearest[pixels2]] ; it takes a bit to run, so I think it is not the right way to group the pixels and measure the similarity


Images used:

What I would expect is a list of coordinates for each image, which are pretty similar in both. Is there any way to do this using Mathematica software? This problem could be also interpreted as "spot the differences", if you prefer.

• Welcome to Mathematica Stack Exchange! What have you tried so far? Is this related to ImageCorrespondingPoints? Do you have an example pair of images that you can share? – C. E. Sep 29 '19 at 16:23
• Hi C.E.. I edited the question. Thanks – still_learning Sep 29 '19 at 18:06

Perhaps this can help.

img1 = Import["https://i.stack.imgur.com/agPud.jpg"];
img2 = Import["https://i.stack.imgur.com/dCNCz.jpg"];
aligned = RemoveAlphaChannel@ImageAlign[img2, img1];
img2 - aligned // ImageAdjust // RemoveBackground All the white pixels are the pixels that are the same in both images.

Usually, for these types of images, just subtraction should be enough, but since the sizes of the images are different, alignment is also necessary.

• Thank you, C.E.. In case the size of the images is different, what do you suggest to do? – still_learning Sep 29 '19 at 18:56
• @Matt My suggestion is in my answer. I'm saying that because your images are of different size (their widths are different) I cannot use simple subtraction, I need to use ImageAlign as well. – C. E. Sep 29 '19 at 19:29