简体   繁体   English

在另一个蒙版(或 AND 条件)上应用蒙版以进行图像分析

[英]Applying a mask on another mask (or AND condition) for image analysis

I'm trying to do an AND operation on two masks to get their co-positive pixels but it doesn't seem to work - I get the original mask somehow after the AND operation:我正在尝试对两个蒙版进行 AND 操作以获得它们的共同正像素,但它似乎不起作用 - 在 AND 操作之后我以某种方式获得了原始蒙版:

plt.imshow(mask);plt.show()
plt.imshow(other_mask);plt.show()
masked_both = cv2.bitwise_and(mask, other_mask)
plt.imshow(masked_both);plt.show()

输出

What's the right way to do it?正确的方法是什么? Thanks谢谢

Is is most likely that other_mask contains only positive values, but imshow scales the values.很可能other_mask仅包含正值,但imshow缩放值。 For example, min value of other_mask can be 100 and displayed as purple, and max value can be 200 and displayed as yellow.例如, other_mask的最小值可以为 100 并显示为紫色,最大值可以为 200 并显示为黄色。 In that case masked_both will be the same as mask.在这种情况下, masked_both 将与 mask 相同。 You can check this by inspecting min and max values of your masks.您可以通过检查掩码的最小值和最大值来检查这一点。

If this is the case, you can fix it by normalizing value ranges of both masks:如果是这种情况,您可以通过标准化两个掩码的值范围来修复它:

min_value = mask.min()
max_value = mask.max()
masked_normalized = (mask - min_value) / (max_value - min_value)

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

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