I have an image master.png
and more than 10.000 of other images (slave_1.png
, slave_2.png
, ...). They all have:
- The same dimensions (Eg. 100x50 pixels)
- The same format (png)
- The same image background
98% of the slaves are identical to the master, but 2% of the slaves have a slightly different content:
- New colors appear
- New small shapes appear in the middle of the image
I need to spot those different slaves. I'm using Ruby, but I have no problem in use a different technology.
I tried to File.binread
both images and then compare using ==
. It worked for 80% of the slaves. In other slaves, it was spotting changes but the images was visually identical. So it doesn't work.
Alternatives are:
- Count the number of colors present in each slave and compare with master. It will work in 100% of the time. But I don't know how to do it in Ruby in a "light" way.
- Use some image processor to compare by histograms like
RMagick
orruby-vips8
. This way should also work but I need to consume the less CPU/Memory possible. - Write a C++/Go/Crystal program to read pixel by pixel and return a number of colors. I think in this way we can get performance out of if. But for sure is the hard way.
Any enlightenment? Suggestions?