Compare 2 16x16 pixel images similarity

10,398

Solution 1

Use a count for the number of pixels that don't match:

public const double PERCENT_MATCH = 0.9;

int noMatchCount = 0;
for (int x = 0; x < irMainX; x++)
{
    for (int y = 0; y < irMainY; y++)
    {
       if ( !pixelsMatch( image.GetPixel(x,y), srClickedArray[x%16, y%16] )
       {
           noMatchCount++;
           if ( noMatchCount > ( 16 * 16 * ( 1.0 - PERCENT_MATCH ))
              goto matchFailed;
       }
    }
}
Console.WriteLine("images are >=90% identical");
return;
matchFailed:
Console.WriteLine("image are <90% identical");

You could count matching pixels, but that will be slower. Consider measuring how much two pixels differ. For most purposes - you could have ALL the pixels not match exactly - yet have the images look visually identical

Solution 2

I wouldn't use image.GetPixel(x,y), as it's a lot slower than utilizing unsafe code to check specific bytes associated with each image.

Check out Lockbits

Share:
10,398
MonsterMMORPG
Author by

MonsterMMORPG

Hello. I am the only owner and developer of web based online MMORPG game MonsterMMORPG. I am a computer engineer from Turkey and i am currently doing MA at computer engineering. I am specialized with C# &amp; ASP.net. http://www.monstermmorpg.com/ MonsterMMORPG is a Free To Play Browser Based Online Monster MMORPG Game Better Than Online Pokemon Games You will love it's awesome Monsters We have many different unique features. So i suggest you to check them out. Our game is similiar with Pokemon games but it is unique. Like diablo and torch light. You should visit following sites related to us MonsterMMORPG Facebook Pokemon Games Lovers Facebook Application MonsterMMORPG Youtube Channel Monster Game Forum Canavar Oyunu Forum Pokemon Fakemon DeviantArt MonsterMMORPG Google Plus MonsterMMORPG Twitter MonsterMMORPG Review On Browsergamez MonsterMMORPG Review On mmohuts MonsterMMORPG Developer Blog At MMORPG.com MonsterMMORPG Review On onrpg MonsterMMORPG On GameSpot MonsterMMORPG Wiki MonsterMMORPG On 1UP MonsterMMORPG Digg MonsterMMORPG Official Google Plus Page

Updated on June 04, 2022

Comments

  • MonsterMMORPG
    MonsterMMORPG almost 2 years

    I would like to compare 2 images similarity with percentage. I want to detect 90% same images. Each image size is 16x16 pixel. I need some clue, help about it. Right now i am able to detect 100% same images when comparing with the code below

    for (; x < irMainX; x++)
    {
    
        for (; y < irMainY; y++)
        {
            Color pixelColor = image.GetPixel(x, y);
            if (pixelColor.A.ToString() != srClickedArray[x % 16, y % 16, 0])
            {
                blSame = false;
                y = 16;
                break;
            }
            if (pixelColor.R.ToString() != srClickedArray[x % 16, y % 16, 1])
            {
                blSame = false;
                y = 16;
                break;
            }
            if (pixelColor.G.ToString() != srClickedArray[x % 16, y % 16, 2])
            {
                blSame = false;
                y = 16;
                break;
            }
            if (pixelColor.B.ToString() != srClickedArray[x % 16, y % 16, 3])
            {
                blSame = false;
                y = 16;
                break;
            }
        }
    
        y = y - 16;
    
        if (blSame == false)
            break;
    }
    

    For example i would like to recognize these 2 images as same. Currently the software recognizes them as different images since they are not exactly same

    enter image description here enter image description here