0

I am looking for a C++ or Python library to compare two JPEG or BMP formatted Images. Here, I want to compare them pixel wise. For instance assume we have Image1 = 500 pixels, Image2 = 500 pixels; now i need to know the color values ie (RGB, R = 24, G = 15, B = 4) for each pixel and compare the same with image2 at the same location.

I also need to have tolerance values acting upon them, if they still have difference crossing this tolerance then i need to have the total percentage difference.

Is there a library out there ? If so please point me to that or give me any suggestions to start with.

GWW
  • 43,129
  • 11
  • 115
  • 108
Santhosh Balasa
  • 186
  • 3
  • 11
  • Hi Santy: Since this is your first question I'll just comment and not downvote you. You need to do research before asking a question here. Read http://stackoverflow.com/faq for details. If you just google "image comparison library" you'll get the answer for your question quite fast. (Heck you can qualify it with C++ or Python too :) – Ahmed Masud Nov 20 '11 at 15:10
  • With or without tolerance, you really don't want to compare BMPs and JPEGs pixel by pixel. – NullUserException Nov 20 '11 at 15:11
  • http://stackoverflow.com/questions/796364/fast-cross-platform-c-c-image-processing-libraries has answers for you – Ahmed Masud Nov 20 '11 at 15:12

4 Answers4

3

If all you need to do is just comparison pixel-wise, you might achieve better performance by using numpy.

Numpy is an extremely fast python module that works with n-dimensional arrays (containing all the same type, as it is in the case of pixel data) and by operating on them element-wise.

So, "tell me were the alpha value of the pixels of two images differs by more than 0.5" would be translated in something like:

img_one[..., ALPHA] - img_two[..., ALPHA] > 0.5

HTH!

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
mac
  • 42,153
  • 26
  • 121
  • 131
1

I'd suggest OpenCV. It's written in C, but there are bindings for Python as well. There are probably other solutions as well (e.g. doing it "by hand" yourself or using another library), but I'd say it's by far the most popular imaging library available.

E.g. you could create a new image with the differences between both images and then count different pixels or judge your result depending on its colors etc.

Mario
  • 35,726
  • 5
  • 62
  • 78
  • from version 2.0 opencv is in c++ not in c – Boaz Nov 20 '11 at 15:15
  • Interesting, haven't used it in ages. Everything nice and with classes? Might have a look later on. – Mario Nov 20 '11 at 15:16
  • yes, everything was rewritten, classes and all. but you can still use the old c syntax with the overhead of translating all the CvMats and IplImages into cv::Mat in the framework inner functions – Boaz Nov 20 '11 at 15:21
1

Did you try OpenCV ; it uses C++ .

Sujay Ghosh
  • 2,828
  • 8
  • 30
  • 47
1

I might check out Python Image Library, the Image Module's, getdata() and getpixel() sound like they'd be useful for you.

ben author
  • 2,855
  • 2
  • 25
  • 43