Image comparison - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Image comparison

Anyone knows of any algorithm, library, C++ class or whatever I can use to do some bitmap comparison?


  • XLoomXLoom Posts: 129Member
    Hi there
    Do you mean by bitmap comparison that you want to know how much one bitmap resembles the other in for example percentage? If so, then I hope this code helps a bit.

    This code would compare two currently 100x100 bitmaps and give you the percent of how similar they are. However, it isn't the same thing human brain performs... :)

    // definition of both bitmaps height and width
    #define BITMAPX 100
    #define BITMAPY 100

    // structure to contain data for one pixel
    typedef struct {
    float r,g,b; // color data varies for each color from 0-255
    }RGB; // they are floats just for convinience

    // two 100x100x24 bit bitmaps containing about to be compared images
    RGB bitmap1[100][100],bitmap2[100][100];

    // variables to hold number of pixels, current pixel and match so far
    // and match for current pixel
    float pixels=BITMAPX*BITMAPY,current_pixel=0;
    float match=0,currentmatch=0;

    // now we start looping through all pixels in our bitmaps comparing
    // according pixels to each other
    for(int posx=0;posx<BITMAPX;posx++){
    for(int posy=0;posy<BITMAPY;posy++){

    // this is where actual comparison takes place
    // given that all three basic colors are on different axis
    // match between them can be calculated using
    // vector length equation



    Match should now be the similarity in percent between two bitmaps. If everything is correct, because I don't have time to test this code. And actually I doubt if this is the code you want. But maybe it is of some help.


Sign In or Register to comment.