1

I have images that I upload to a server using Amazon S3. I convert them to NSData, using UIImageJPEGRepresentation with 0.75f compression quality. Now I'd like to compare them and see if they are equal.

With PNG, it's easy, all I had to do is this:

if (UIImagePNGRepresentation(self.pictureImageView.image) isEqual:
             UIImagePNGRepresentation(manageItemVC.pictureImage)]) {}

as stated here. And that would work, but now the images are JPEG, and the comparison isn't working (most likely due to compression), even if I use UIImageJPEGRepresentation.

self.pictureImageView.image is the image from the server that I've loaded into an UIImageView, and manageItemVC.pictureImage is an image that the user picked from the photo library.

Anyone know how to compare JPEG images?

Community
  • 1
  • 1
swiftcode
  • 3,039
  • 9
  • 39
  • 64
  • Try setting the compression quality to 1 to see if it's definitely the compression that's the difference. – Matt S Jul 12 '13 at 20:44
  • Apparently it's not the issue, with 1 it's still not working. – swiftcode Jul 12 '13 at 20:53
  • 2
    Technically the PNG representations of images aren't unique; in PNG land you pick a linear predictor per scan line and you usually pick that by taking a guess at which will produce the simplest (ie, easiest to gzip compress) output. It's a pretty safe bet that `UIImagePNGRepresentation` will always make the same choices but it isn't a contractual requirement. – Tommy Jul 12 '13 at 20:56
  • Is there some sort of library or algoritm for JPEG image comparisons with reasonable results? – swiftcode Jul 12 '13 at 21:00

1 Answers1

0

You can check data's length of two image and compare it. With my suggestion, i check if two data different about 10000 => two image different.