Image Compare By Pixels

How to compare 2 images to check if it is identical. The easiest way is to compare pixel by pixel of the 2 images.

In my example, I am using Python Pillow to compare. To install it in macOS, just run these 2 lines

python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

For other OS, you can refer to their official site at https://pillow.readthedocs.io/en/stable/installation.html

The source code of my function

WebP

  1. I downloaded a 360x360 WebP image from Google PlayStore and named it a.webp
  2. Duplicate a.webp to b.webp
  3. Edit 1 pixel in b.webp in GIMP

PNG

  1. Converted a.webp to a.png using ImageMagick
  2. Duplicate a.png to b.png
  3. Edit 1 pixel in b.png
convert a.webp a.png

BMP

  1. Converted a.webp to a.bmp using ImageMagick
  2. Duplicate a.bmp to b.bmp
  3. Edit 1 pixel in b.bmp
convert a.webp a.bmp

GIF

  1. Converted a.webp to a.gif using ImageMagick
  2. Duplicate a.gif to b.gif
  3. Edit 1 pixel in b.gif
convert a.webp a.gif

JPG

  1. Converted a.webp to a.jpg using ImageMagick
  2. Duplicate a.jpg to b.jpg
  3. Edit 1 pixel in b.jpg
  4. Save as 100% quality
convert a.webp a.jpg

Conclusion

My favorite file type is PNG although GIF has a smaller file size because GIF looks grainy after the conversion with default settings.

Works with
- GIF, PNG, BMP

Does NOT work with
- WebP, JPG

Related articles

Jigsaw Search In Image (version 1)
Needle In Haystack Search (version 2)

< Back to all the stories I had written

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kevin FOO

A software engineer, a rock climbing, inline skating enthusiast, a husband, a father.