Image Comparison using Python

Hello eveyone,

I am still very much a beginner in programming but i was looking for an open Python code that takes two images as an input, compares the images (either as a simple RGB value pixel by pixel comparison, or by using computer vision AI, or any other method…) and then highlights the similarities and difference in different colors. I often need to compare pictures in my work-flow and thought i could make things easier by using a program for that.

I would be very thankful for any suggestions and comments.

Well, the Pillow library loads images in various formats.

The GraphicsMagick or ImageMagick libraries also load various formats
and provide various manipulation facilities; I can’t recall whether they
do image differencing. There’s at least one Python wrapper for these on
PyPI (pymagick).

Doing bulk computation on data is done by the numpy package; it may be
amenable to working with a matrix of pixel values if you extract those
values from an image loaded by one of the preceeding image libraries.
Load image, make pixel matrices, work with numpy, convert the result
back to an image maybe.

You can also go the crude brute force black box approach of noting that
video formats gain a lot of compression by storing difference frames,
where video frame n+1 is computed from the previous frame plus a much
smaller difference frame. So I’d suppose you could write a 2 frame video
as 2 image files, then tell an external tool like ffmpeg to assember
those 2 frames into a video, the extract the difference from from that.
Off loads all the work to ffmpeg. And of course tells you nothing about
how it was done.

Have a look on for (a) image libraries like Pillow or
{Image,Graphics}Magick and (b) computation libraries like numpy.

Cameron Simpson

Thank you very much for your reply and your recommendations! I will give it a look :grinning_face_with_smiling_eyes: