0

I was playing around with images and came across a little game I tried to create.

You see an Image (for simplicity let's say a circle) and you have to redraw the circle as exact as possible on top of it.

All of that works in my little project already.

I want to be able to tell how many % of the image was recreated correctly (and again for simplicity no colours needed. It's always black and white)

Could I just count the the black pixels overlaying the image subtract the ones that are not and divide it by the amount of black pixels in the original? This would look like this I guess:

ratio = (correctPixelCount - wrongPixelCount) / originalPixelCount

If yes, how would I go about getting each pixel and compare them? If no, what else could I do?

PS: I already tried a Image compare cocoa pod called AIImageCompare. Unfortunately it crashes for some unknown reasons.

Thank you!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
smnk
  • 471
  • 1
  • 6
  • 25
  • What if you compare positions and bounds instead of pixels? It will be much faster – Guilherme Campos Hazan Nov 09 '16 at 16:49
  • Position and bounds won't tell me about the actual image? Or maybe I don't really understand what you mean ? Also those images won't be bigger than 256x256 pixel and a little waiting time would be OK – smnk Nov 09 '16 at 16:50
  • It depends on the kind of game. If its something like pacman or space invaders, or even like Snake, then testing the position of the elements for a collision detection is enough. You dont need to test pixels, unless the objects are quite irregular. – Guilherme Campos Hazan Nov 09 '16 at 17:33
  • Well I assume it is quite irregular when you try to draw a perfect circle with your finger on a screen – smnk Nov 09 '16 at 17:37
  • One possible solution to iterate over the pixels can be found here: http://stackoverflow.com/a/31111515/1457385 – shallowThought Nov 09 '16 at 17:39

0 Answers0