Home > Net >  Detecting image change by its binary size only
Detecting image change by its binary size only

Time:11-22

The binary size of an image file is affected by changing a single pixel. I'm curious if comparing the binary sizes of two photos is enough to detect a change! Will there be any false-positive outcomes? How reliable is this solution?

The images I'm comparing are in the 'PNG' format, and they're snapshots from the same source, so the quality and dimensions are identical, but the pixels may differ.

I'm aware of libraries like pixelmatch and img-diff-js, but they're too slow for my purposes, and I don't require extensive diff findings; just true/false will suffice.

CodePudding user response:

Assuming PNG files acquired and compressed by the same system, most files will have approximately the same size. A small change could cause the comprised image to be a byte longer or shorter, but there will be many, many different images with exactly the same file size.

But to find identical images you don’t need to decompress the PNG files, the compressed data will be identical for identical images, and different for different images. Also just comparing the files byte by byte will tell you if they contain identical images or not.

However, this is true only for identical images. If we’re talking about a camera producing a stream of images, and you wanting to know if something changed in the scene, then you will still have to compare the decompressed images. This is because the data will contain noise, and the noise will cause the compressed files to not be identical. And you can’t tell from the compressed file if the change is due to noise or a more important change. In this case, you will have to decompress the images, and compare them with some tolerance.

  • Related