1

I want to find duplicate photos from photo library fast I'm using following code for retrieving duplicate image but its time taking :

UIImage *img1 = [imgArray objectAtIndex:i];
UIImage *img2 = [imgArray objectAtIndex:j];

NSData *data1 = UIImageJPEGRepresentation(img1, 1.0);
NSLog(@"%@",data1);
NSData *data2 = UIImageJPEGRepresentation(img2, 1.0);
NSLog(@"%@",data2);


            if ([data1 isEqualToData:data2])
            {
                    [duparray addObject:[imageArray objectAtIndex:i]];
                    [duparray addObject:[imageArray objectAtIndex:j]];
            }
            else
            {
                NSLog(@"no");
            }

getting the data and comparing 1000 photos waste of time can anyone help me for this, help will be appreciated.. thank you

Mitesh Varu
  • 123
  • 1
  • 10

2 Answers2

0

The code you are using to compare two images will be comparing both images bit by bit for equality. If you shoot similar pics, the comparison will lead to inequality. If you want duplicate pics removed that have same data composition, the current code will be working fine. If you want to include similar pics to pass equality test, you need to use different logic to compare. And btw, do not run this code in main thread. Run it asynchronously if it's a long-running task.

When using UIImageJPEGRepresentation, try to compress (0.5 or lower) the images instead of setting the quality to 1.0, which might lead to some improvement.

To compare images, and check if they're similar to a certain percentage, you can check out this answer from SO:

Compare one image to another to see if they are similar by a certain percentage

badhanganesh
  • 3,427
  • 3
  • 18
  • 39
  • can you suggest me some logic for that? I'm searching for that logic only...@Badhan Ganesh – Mitesh Varu May 25 '17 at 09:07
  • what about width, height and the getRGBForX ? thats not mention in that answer brother.... – Mitesh Varu May 25 '17 at 10:42
  • can you suggest another way of comparing image which just slightly different from each other? – Mitesh Varu May 26 '17 at 10:56
  • You can check this answer (https://stackoverflow.com/a/19668235/5912335) from the same post I shared. I haven't tried it, but you'll get full implementation and usage of the image comparison. Hope that helps solve your problem. – badhanganesh May 26 '17 at 11:05
  • i tried this its not working for me because if the image is little bit different then it will not return true for duplicate image suppose i take two images i 1st image I'm standing in the middle of the image and in another i standing little bit away from the centre with the same pose then this will not work of me and one image is blur and another is clear then also it will not return true its becoming headache now please help me to get out of this – Mitesh Varu May 26 '17 at 11:13
  • Yeah! Because pixels from two images differ more than we see directly with our eyes .. It's tricky to get this working. This is what google announced in Google IO 2017. They use machine learning to identify similarities in images and they seem to use Complex algorithms to process the images to know whether they are really similar as wee see it with out eyes. – badhanganesh May 26 '17 at 11:16
  • yap!! and i searched on app store there are only 2 apps for removing duplicate images don't know what logic they have applied behind it check out if you get some logic form that photo cleaner is the name this is link https://itunes.apple.com/in/app/cleaner-delete-duplicate-photos-clean-storage/id1185450847?mt=8 – Mitesh Varu May 26 '17 at 12:00
  • have you got any logic related what he must have done ......?@Badhan Ganesh – Mitesh Varu May 29 '17 at 04:33
0

A similar topic is discussed and there are good suggestions. Reading can be beneficial.

Image comparison - fast algorithm

g89n7man
  • 59
  • 1
  • 1
  • 6