1

i am comparing images with each other here is the code for it.

for (int i=0; i<arrImageData.count; i++) { for (int j=i+1; j<arrImageData.count; j++) { if ([arrImageData[i]isEqualToData:arrImageData[j]]) { [arrImages addObject:arrImage[i]]; } } } 

now problem is when number of images increase it takes too much time to calculate.is there any better solution for it?

8
  • I think That's not how Images are compared. Commented Dec 16, 2015 at 12:30
  • assume there aree 1000 images...so it compare 1st image with other 999 images...after that 2nd image will compare with other 998 image..and so on...so it takes too much time to compute..give me better solution for this issue Commented Dec 16, 2015 at 12:31
  • Oh sorry. You are comparing NSData. Thats fine then. Commented Dec 16, 2015 at 12:33
  • yes.. i am comparing nsdata comparison works perfect but it takes time when there is high number of images Commented Dec 16, 2015 at 12:35
  • this comparison is works when data is exact copy of that data....if i want to do like "if 10% of image is same then it count as same image"..any solution for this?? Commented Dec 16, 2015 at 12:43

4 Answers 4

1

I think you should use hashes for comparison. Refer this link: Generate hash from UIImage It will help you.

Sign up to request clarification or add additional context in comments.

Comments

1

you should use hashes to compare big amount of data

1 you can compare UImage directrly: image1.hash == image2.hash

2 you can calculate your own hash for each image added to the array, it will be calculated once and used for every comparison

here is the hash algorithm https://en.wikipedia.org/wiki/MD5

PS it will works if image data is absolutely equal, it much more difficult to compare two different images with one "content" Image comparison - fast algorithm

2 Comments

but i am comparing images one by one with each other thats why it takes too much time...anyother algorithm you suggest
This should probably be a comment and not an answer.
0

you can try something like this:

- (BOOL)image:(UIImage *)image1 isEqualTo:(UIImage *)image2{ return [UIImagePNGRepresentation(image1) isEqual:UIImagePNGRepresentation(image2)]; } 

2 Comments

That's what he is doing. He wants to do it faster as he has a large set of images
this is the same as i m doing...i want faster method to compare lots of images...
0

You can use Fast Enumeration as Below

 for(UIImage *img in arrImageData) { for (UIImage *comImg in arrImageData) { if ([UIImageJPEGRepresentation(img, 0) isEqual:UIImageJPEGRepresentation(comImg, 0)]) { [arrImages addObject:img]; } } } 

Hope it helps you...!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.