Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any simple way to test two PNGs for equality?

I've got a bunch of PNG images, and I'm looking for a way to identify duplicates. By duplicates I mean, specifically, two PNG files whose uncompressed image data are identical, not necessarily whose files are identical. This means I can't do something simple like compare CRC hash values.

I figure this can actually be done reliably since PNGs use lossless compression, but I'm worried about speed. I know I can winnow things down a little by testing for equal dimensions first, but when it comes time to actually compare the images against each other, is there any way to do it reasonably efficiently? (ie. faster than the "double-for-loop checking pixel values against each other" brute-force method?)

like image 777
Mason Wheeler Avatar asked Mar 21 '10 18:03

Mason Wheeler


People also ask

How can you tell if two pictures are the same?

Compare Brightness as half the weight and compare color/hue as the other half (or 2/3rds vs 1/3rd). Calculate the difference in values and depending on 'tolerance' value they are the same or they are not. JPEG heavily compresses the color information but tries not to ruin the liminance values. Save this answer.

How do I compare two pixels in a picture?

The general idea is very simple - pixel-by-pixel comparison. The comparison engine gets the color of pixels that have the same coordinates within the image and compares this color. If the color of each pixel of both images coincides, TestComplete considers the two images to be identical.

What is a PNG test?

English: This is a temporary file for testing of correct rendering of PNG files. This file can be modify by anyone, to test their own PNG. If you suspect a problem with the rendering of your graphic, then upload it the first time here (it's easier than delete an upload).


2 Answers

  1. filter by identical image size (width & height)
  2. open file
  3. hash uncompressed contents (md5 would do probably)
  4. store hash

  5. compare hashes to find identical ones

like image 148
ChristopheD Avatar answered Oct 11 '22 14:10

ChristopheD


Instead of looping through all pixels in order to check equality, it might be worth while starting from the middle and working your way outwards. Most pictures have the subject in the middle meaning more feature data is located here. Essentially it will be lots quicker to find out if two pictures are different this way.

like image 36
Chris Avatar answered Oct 11 '22 14:10

Chris