Using Objective-C, is there any way to compare two images and get a % difference value returned?
For example, one image will have and X in it. Another image will ha
Pixel by pixel comparison wouldn't help if source image size and destination image size is different. In this case the scaling ration should be correct. any other solutions for this?
You can use OpenCV (Open Source Computer Vision) library in iphone.This question has a good discussion on image comparison algorithms. Image processing on the iPhone this link may be helpful.
You are going to have to think quite carefully about what kind of differences you care about.
Doing a pixel-by-pixel comparison of identically sized images won't be too hard. Assign an error value to each pixel, and then somehow combine the differences to produce a single figure.
Scaling one or other image if they start off different sizes but the same aspect ratio is also fairly simple.
However, the edge cases get tricky very quickly. For example, what happens if your two X characters are displaced, so one is on the left of the image, and the other on the right? Should these be detected as "similar" somehow?
Also, when comparing H to X, you want a high score - but how then would you rank an X against a colour picture of a butterfly? Even higher, presumably, but how much higher?
Some kind of learning neural network might help you, where you work out what values you would assign yourself to some sample comparisons, then train the network to return those values for your sample images. But that isn't trivial to code.
If your comparison requirements are simpler - for example, you are doing some kind of OCR equivalent, and you know that your inputs are likely to be monochromatic characters, then there are other tricks you can use - but the appropriate ones will depend on what you are trying to achieve.
The API's have nothing like this available.
If you want to do this you'll have to roll your own or use an external library.
I would suggest finding an external library as this is not a trivial task.
For example, You have two images with an x the same font and color. Are the images the same size? If not, are they considered 100% different? If you resize the images to match, the difference is going to be much higher than it would be otherwise.
Or, let's say that you have two images with an x the same font and image size, but the colors are different. How would you weight that as a percent? Totally different or partially different? If you say that color is only partially different then how would you ever get a 100% difference?
Regardless, the basic way to do this (this I can see, I am sure someone much smarter will have a better idea) is to go pixel by pixel and compare the color data (HSV might be a good choice for this). Weight the components and calculate your difference.