简体   繁体   English

如何比较二进制图像并在python中验证几乎相等?

[英]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. 现在,我想检查操作后的2张图像是否几乎相同(95%),而不是每一位。

How can i change it? 我该如何更改?

Assuming that by "binary image" you meant a 1-bit bitmap image (an image with 1-bit per pixel). 假设“二进制图像”是指1位的位图图像(每像素1位的图像)。

If the two images have the same size, you can do a bitwise XOR of the two bitmaps. 如果两个图像的大小相同,则可以对两个位图进行按位XOR。

The truth table for bitwise XOR operation is: 按位XOR操作的真值表为:

 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. 然后,您可以在位串中找到1的数量,以获取两个图像之间变化的像素数量。

Anderson's Bit Twiddling Hacks page gives several different strategies for efficiently counting the number of bits in an integer/bitset. Anderson的“ Bit Twiddling Hacks”页面提供了几种不同的策略,可以有效地计算整数/位集中的位数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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