I need to compare images about 2000 images but looping into the images use all the processors.
Here is how I'm comparing the images:
NSImage *file = [[NSImage alloc] initWithContentsOfFile:path];
NSImage *fileTwo = [[NSImage alloc] initWithContentsOfFile:pathTwo];
NSData *imgDataOne = [file TIFFRepresentation];
NSData *imgDataTwo = [fileTwo TIFFRepresentation];
if ([imgDataOne isEqualToData: imgDataTwo])
{
NSLog(@"is the same image");
}
I'm doing something wrong in the comparison or how can I compare the images without taking over the processors of my computer?
The fastest way is to get a list of all the files and then, for each one, get its size and then say that files that are not the same size cannot be equal. That is fast, since it doesn't even require you to read the files from disk.
Once you find two, or more files of equal size, you can MD5 checksum them to see if the contents are identical - if you store the MD5 checksums as you calculate them, it is again faster than comparing every pair of files since you only read each file once.
There is certainly no need to create the TIFFRepresentation of each file...