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?

Irfan
  • 5,070
  • 1
  • 28
  • 32
Harshit
  • 184
  • 9
  • I think That's not how [Images are compared](http://stackoverflow.com/questions/7749862/using-objective-c-is-there-any-way-to-compare-two-images-and-get-a-difference). – NSNoob Dec 16 '15 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 – Harshit Dec 16 '15 at 12:31
  • Oh sorry. You are comparing NSData. Thats fine then. – NSNoob Dec 16 '15 at 12:33
  • yes.. i am comparing nsdata comparison works perfect but it takes time when there is high number of images – Harshit Dec 16 '15 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?? – Harshit Dec 16 '15 at 12:43
  • @Harshit But that's a completely different question. You'd first need to precisely define that partial equality. – meaning-matters Dec 16 '15 at 12:50
  • i would ask diffrent question but then i think add into this... – Harshit Dec 16 '15 at 12:59
  • Idk if hashes work this way (Comparison by percentage) but if you compare images pixel by pixel, you can see how much percent of images match each other. See accepted answer in my first comment – NSNoob Dec 16 '15 at 14:03

4 Answers4

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

Community
  • 1
  • 1
Igor
  • 1,537
  • 10
  • 12
1

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

Community
  • 1
  • 1
Nilesh
  • 438
  • 5
  • 15
0

you can try something like this:

- (BOOL)image:(UIImage *)image1 isEqualTo:(UIImage *)image2{    
    return [UIImagePNGRepresentation(image1) isEqual:UIImagePNGRepresentation(image2)];
}
Jiri Zachar
  • 487
  • 3
  • 8
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...!

Vidhyanand
  • 5,369
  • 4
  • 26
  • 59