0

I have two binary images and I use this:

chiusa = ~(imgsk == img2).all()

to check after an operation if change something in the image. Now i would like to check if the 2 images after the operation is almost the same (95%) and not every bit.

How can i change it?

merlin2011
  • 71,677
  • 44
  • 195
  • 329
postgres
  • 2,242
  • 5
  • 34
  • 50
  • This might help: http://stackoverflow.com/a/1072576/287491 If speed isn't an issue you could read one bit from each file, compare them, store the result and at the end compute the difference based on those results. – Virgiliu Apr 13 '14 at 17:31
  • How exactly are your "binary images" represented in memory? If you provide some code used to generate them, we may be able to help you better. – merlin2011 Apr 13 '14 at 17:36

1 Answers1

0

Assuming that by "binary image" you meant a 1-bit bitmap image (an image with 1-bit per pixel).

If the two images have the same size, you can do a bitwise XOR of the two bitmaps.

The truth table for bitwise XOR operation is:

 a  b | o
------+---
 0  0 | 0
 0  1 | 1
 1  0 | 1
 1  1 | 0

Then you can find the number of 1s in the bitstring to get the number of pixels that changes between the two images.

Anderson's Bit Twiddling Hacks page gives several different strategies for efficiently counting the number of bits in an integer/bitset.

Lie Ryan
  • 62,238
  • 13
  • 100
  • 144