3
$\begingroup$

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:

enter image description hereenter image description here

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.

$\endgroup$
2
  • 1
    $\begingroup$ 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? $\endgroup$
    – C. E.
    Sep 29, 2019 at 16:23
  • $\begingroup$ Hi C.E.. I edited the question. Thanks $\endgroup$ Sep 29, 2019 at 18:06

1 Answer 1

4
$\begingroup$

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

Mathematica graphics

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.

$\endgroup$
2
  • $\begingroup$ Thank you, C.E.. In case the size of the images is different, what do you suggest to do? $\endgroup$ Sep 29, 2019 at 18:56
  • $\begingroup$ @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. $\endgroup$
    – C. E.
    Sep 29, 2019 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.