如何“归零"? OpenCV中图像的蒙版部分中的所有内容 [英] How to "zero" everything within a masked part of an image in OpenCV

查看:79
本文介绍了如何“归零"? OpenCV中图像的蒙版部分中的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个图像(8位IplImage)和一个二进制掩码(也就是相同大小的8位IplImage,其中每个像素的值为0或255),我该如何使每个图像中与遮罩中的像素值为零相对应的像素的值为零,并且图像中与遮罩中的像素具有任何其他值(即255)相对应的每个像素的值都与在原始图像中?

If I have an image (IplImage 8-bit) and a binary mask (which is also an 8-bit IplImage of the same size, where every pixel has a value of either 0 or 255), how can I make every pixel in the image that corresponds with a pixel in the mask with a value of zero have a value of zero, and every pixel in the image that corresponds with a pixel in the mask with any other value (namely 255) have the same value as in the original image?

换句话说,在遮罩区域中"的任何内容都将保持其原始值,而在遮罩区域之外的任何内容都将变为零.

In other words, anything that is "in the mask area" will keep its original value, and anything outside the mask area will become zero.

推荐答案

您可以简单地使用bitwise_and()函数.

You can simply use bitwise_and() function.

查看文档.

这篇关于如何“归零"? OpenCV中图像的蒙版部分中的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆