0

This question may seem a duplicate, but it has kind of specific moment that may differ from other questions like this...

So... I have two images. Both are captured the same screen. In my code crops a two(screenCaptureFirst and screenCaptureSecond) big images into small cropped images(each cropped image has 32x32 dimentions). Then I push them into two arrays. And now I have to compare each element of two arrays. - (void) differenceDetector{

int index=0;

for (int currentGridY=0; currentGridY<newCapturedImage.size.height; currentGridY+=gridSize) {
    for (int currentGridX=0; currentGridX<newCapturedImage.size.width; currentGridX+=gridSize) {

        CGRect rect=CGRectMake(currentGridX, currentGridY, gridSize, gridSize);
        UIImage *croppedNewImage=[self croppedImage:rect anImage:newCapturedImage];
        [arrayOfNewImageGrids addObject:croppedNewImage];
        UIImage *croppedOldImage=[self croppedImage:rect anImage:oldCapturedImage];
        [arrayOfOldImageGrids addObject:croppedOldImage];

        if ([[arrayOfNewImageGrids objectAtIndex:index]isEqual:[arrayOfOldImageGrids objectAtIndex:index]]) {
            NSLog(@"Index=%d",index);
        }
        NSLog(@"newGridArray=%@",[arrayOfNewImageGrids objectAtIndex:index]);
        NSLog(@"oldGridArray=%@",[arrayOfOldImageGrids objectAtIndex:index]);
        index++;
    }
}

The problem is when it goes reaches if the result of comparison is FALSE although in arrays are cropped images of the same big image.
Thanks in Advance....

1 Answer 1

1

I doubt very much that UIImage implements -isEqual: (and -hash) to compare the image contents! Almost certainly they just rely on the standard NSObject equality semantics of pointer identity (they only compare equal to themselves).

If you want to compare two images for equality, you'll have to do it yourself. Compare all of their metadata properties. Then, after you're sure all the metadata is equal, obtain the underlying image bits and compare those using memcmp() or NSData.

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

3 Comments

But in my case it's like an array object...And if I put both the same image variable(newCapturedImage,oldCapturedImage) I have success. But if image variables are different then it fails.
"like an array object"? What does that mean and how does it address what I've told you? And comparing an object to itself, which is what I think you mean by "if I put both the same image variable ... I have success", will always report equality. That's what I said above.
OK I got your point. Now it's clear... I can't compare two different images. If I want to do it I must compare them pixel by pixel...right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.