简体   繁体   中英

How can i compare to binary images and verified are almost equal in python?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM