Marco Manzoni
Marco Manzoni

Reputation: 707

Image/Color Comparison in Objective-C

I'm trying to find a way to compare two images. Let me give you an example so you can better understand: my App will randomize a color (she will randomize a value from 0 to 255 for the R, then for the G and then for the B and the result is a completely random RGB color). Now the user will take a photo from the camera of the iPhone and the App will comprare the color with the image. Example: The App select the RGB = 205,133,63 wich is brown: the user will take a picture of a brown detail of a desk. Now I need to compare the brown selected by the iPhone and the brown of the picture and display a result (for example: "the pictures is faithful to 88% compared to the given color"). I found this example in internet, but I can figure out how I can implement this in my App: http://www.youtube.com/watch?v=hWRPn7IsChI

Thanks!!

Marco

Upvotes: 0

Views: 803

Answers (1)

BlueVoodoo
BlueVoodoo

Reputation: 3686

There are plenty of ways you can do this. If you want to keep it simple, you can average the colours for your entire image. For the sake of simplicity, let's say your image only has two pixels: RGB0 = 255, 0, 0 (red) RGB1 = 0, 0, 0 (black)

Average between the two will be RGB_AVG = 128, 0, 0 (dark red)

Now you can calculate the difference between this average and the selected colour 205, 133, 63. This too you can do in many different ways. Here is one:

R = 205 - 128 = 80 
G = 133 - 0 = 133
B = 63 - 0 = 63
Total = 80 + 133 + 63 = 276

Total score = (756 - 276) / 756 = 63.5%

This is just one way, you could collect all colours in a dictionary and count them if you need it to be super accurate. It all depends on what you want to achieve.

Btw: Reassure your numbers don't end up being higher if they are higher than your sample color. Use ABS or whatever method you want. The above is just an example.

Upvotes: 1

Related Questions