how to calculate the similarity of two black-white picture like the attachment

Tags: ,



One picture is used for the user to imitate. Another picture is drawed by user. I want to calculate the similarity of two. I tried to convert the picutre data to binary list and calculate the same data, but I realize it’s not working because there’s a lot of while pixel beyond the drawing. Anyone can help on this ? Thanks a lot. two picture:

Now I use the following method:

  for (var y = 0; y < 50; y=y+1){
for (var x = 0; x < 50; x=x+1){
  if(compareArray[0][x][y]){
    total1 = total1 + 1; 
    if(compareArray[1][x][y]||compareArray[1][x-1][y-1]||compareArray[1][x][y-1]
      ||compareArray[1][x+1][y+1]||compareArray[1][x-1][y]||compareArray[1][x+1][y]
      ||compareArray[1][x-1][y+1]||compareArray[1][x][y+1]||compareArray[1][x+1][y+1]){
        count1 = count1 + 1;
      }
  }
}

} result = count1/total1

Answer

you can subtract the pixel of both images, assume image is gray scale, white pixel = 255 and black is 0.

so 255 – 255 = 0 and 0 – 0 = 0, similar pixel will have 0 difference

but different pixel will have high difference.



Source: stackoverflow