0

I want to compare an image that I am downloading from a server to an image saved to the bundle to see if its the same image. How would I accomplish this in iOS?

Thanks!

Shredder

Praxder
  • 2,315
  • 4
  • 32
  • 51

3 Answers3

2

If you want to know if it's the same image then you should just use a hash function.

If you have decided on what hash function should be used then you can even have the server send you the hash of the image and compare it with your local hash of the image instead of sending you the image itself.

If the hash matches then there is no need to download the image at all. If on the other hand the hashes differ then you know that you need to download the new image.

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
  • 1
    I think that even better approach may be to calculate local image hash and send it to server as part of the image request. Then the server will response with the image or with the HTTP code 304 (not modified). The client should then know that he can use stored image. – Ariel Aug 01 '12 at 10:34
2

If images are expected to be exactly the same, not recompressed or anything, you can load both in NSData object and compare it with isEqualToData:.

If they might have different metadata, but the image is still the same, then you can load them as images and compare actual image pixels using decoding similar to this one: How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)?.

If they are similar, but may be of different format or recompressed, then you'd need image comparison software, e.g. OpenCV.

Community
  • 1
  • 1
coverback
  • 4,413
  • 1
  • 19
  • 31
0

firstly you can compare image sizes then sizes are same then you can use answer at Image comparison

Community
  • 1
  • 1
mrcoder
  • 323
  • 4
  • 14