Need a (simple) algorithm to tell if 2 images differ

I have a need to tell if 2 images are different by unimportant details.

For example, one image is only slightly different than another because:

*) It is a little stretched *) or it has 99% portion of another (only missing some pixels on borders)

I wonder if there is an efficient algorithm to achieve my goal. Any suggestions are welcome.

Answered by Claude31 in 746698022

are different by unimportant details.

Your criteria are a bit fuzzy,

  • if only border missing, nearly all pixels are the same

In this case, such algorithm could work: https://stackoverflow.com/questions/6488732/how-does-one-compare-one-image-to-another-to-see-if-they-are-similar-by-a-certai

  • but if stretched, all pixels will be different

This could do it: https://stackoverflow.com/questions/71615277/image-similarity-in-swift

I would also try to compute a similarity distance:

  • split the images in small squares (20*20 for instance), which would make a few hundreds square areas
  • compute the average color of each area
  • Set thresholds: similarity is the % of squares which average color differs less than 10% different; if similarity > 90% then images are "similar": you set 10% and 90% to suit best your need
  • a more sophisticated way would be to compare pixels histograms of the squares: https://developer.apple.com/forums/thread/725550?answerId=746000022#746000022

Hope that helps

Accepted Answer

are different by unimportant details.

Your criteria are a bit fuzzy,

  • if only border missing, nearly all pixels are the same

In this case, such algorithm could work: https://stackoverflow.com/questions/6488732/how-does-one-compare-one-image-to-another-to-see-if-they-are-similar-by-a-certai

  • but if stretched, all pixels will be different

This could do it: https://stackoverflow.com/questions/71615277/image-similarity-in-swift

I would also try to compute a similarity distance:

  • split the images in small squares (20*20 for instance), which would make a few hundreds square areas
  • compute the average color of each area
  • Set thresholds: similarity is the % of squares which average color differs less than 10% different; if similarity > 90% then images are "similar": you set 10% and 90% to suit best your need
  • a more sophisticated way would be to compare pixels histograms of the squares: https://developer.apple.com/forums/thread/725550?answerId=746000022#746000022

Hope that helps

If I were you, I'd start by checking if OpenCV has something that you can use.

If you google "OpenCV image similarity" you'll find some StackOverflow posts with helpful advice.

I fear it is not as simple as you might have hoped.

Hi Imneo,

Note that if you post comments on this forum, it doesn't send notification email like it does for replies. So I suggest always posting replies.

I want to do this in Objective-C. Does anyone have experience on integrating OpenCV into Xcode project?

That's easier than integrating with Swift. Use an objective-C++ (.mm) file to bridge.

There is documentation about building for iOS here:

https://docs.opencv.org/4.x/d5/da3/tutorial_ios_install.html

I've not done that - I've only used OpenCV server-side - but it looks simple enough.

Need a (simple) algorithm to tell if 2 images differ
 
 
Q