3

Say you have two images:

enter image description here

and

enter image description here

These pictures are nearly identical save for a few pixels that are different colors. Is there a native way in Objective-C to identify if two pictures are nearly identical? If not, is there another way to do it?

pasawaya
  • 11,515
  • 7
  • 53
  • 92

3 Answers3

2

My suggestion for identifying if two images are nearly identical is doing a pixel by pixel comparison between both images and keeping track of the similarities as a percentage (or difference since you want to determine if two images are "nearly identical" and the amount of processing/operations for determining differences would be less compared to determining similarities).

Furthermore this is all subjective. Are you referring to "nearly identical" on a pixel level or human eye level? Hope this was helpful :)

David
  • 583
  • 1
  • 10
  • 27
  • That could easily fail. What if the second image is placed upwards by just one pixel, compared with the first? – El Tomato May 10 '13 at 06:50
  • This is assuming the images are taken from the exact position. Otherwise, another method would be needed – David May 10 '13 at 06:55
2

In computer vision and image processing the definition for nearly identical can vary a lot from application to application, therefore the method to calculate similarity/identity will also vary depending on the problem at hand.

In your case it seems that the images have identical resolutions and you are just interested in the number of pixels that are different.

I would suggest that you iterate over both images and XOR the pixel values (if they are identical, the result will be zero).

bjoernz
  • 3,852
  • 18
  • 30
  • I like your last suggestion. I think I'll just XOR the values and see if a certain percentage of the pixels are identical (i.e. 95% are identical, thus the images are very similar). Thanks a lot, will accept. – pasawaya May 10 '13 at 06:38
  • I don't know Cocoa enough, but maybe there is an efficient way to XOR two images by drawing them on top of each other in a special compositing mode. All optimizations have to be measured of course ;-) – bjoernz May 10 '13 at 06:45
1

No, there is definitely no native way to do that in Objective-C – I mean no explicit method on e.g. NSImage. but you can surely do it the hard way, comparing pixel to pixel etc.

Also there is no clear definition of "identical", since two images can seem identical for the human eyes, but can be totally different from another point of view.

Regarding your question which you added in your edit:

There is for example OpenCV, which can do a lot of stuff you could use. Have a look at it OpenCV

…and also there is another nice discussion here on StackOverflow: Image Comparison - fast algorithm

Community
  • 1
  • 1
tamasgal
  • 24,826
  • 18
  • 96
  • 135