Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing two images whether same or not (iOS) [duplicate]

Possible Duplicate:
How does one compare one image to another to see if they are similar by a certain percentage, on the iPhone?

I've found this code and am trying to understand it better:

UIImage *img1 = // Some photo;
UIImage *img2 = // Some photo;

NSData *imgdata1 = UIImagePNGRepresentation(img1);

NSData *imgdata2 = UIImagePNGRepresentation(img2);

if ([imgdata1 isEqualToData:imgdata2]) {
    NSLog(@"Same Image");
}

Will this confirm that image 1 is exactly the same as image 2? Is this method best practice, or is there a better approach to this?

like image 267
PeshZ Avatar asked Dec 29 '12 02:12

PeshZ


People also ask

Can you compare two photos on Iphone?

To compare two photos create an album with two photos, then view them enlarged and switch between the tow photos. i is not possible in Photos iOS. To compare two photos create an album with two photos, then view them enlarged and switch between the tow photos.

How do you compare two images in image processing?

Compare the pictures pixel for pixel, count the matches and the non matches. If they are within a certain threshold of error, you have a match. Otherwise, you could try reducing the resolution up to a certain point and see if the probability of a match improves.

What is image comparison?

An image comparison system that identifies differences utilizing AI image recognition. This is a system that compares two different data sets such as documents, drawings and photos and extracts any image differences between them.


1 Answers

Your code is comparing the two images bit by bit, so yes it's a 100%-comparison.

If you need something faster you can generate an hash from each UIImage and compare the two hashes, as explained here.

like image 194
Gabriele Petronella Avatar answered Sep 20 '22 03:09

Gabriele Petronella