OpenCV功能类似于Matlab的“查找"功能 [英] OpenCV function similar to matlab's "find"

查看:97
本文介绍了OpenCV功能类似于Matlab的“查找"功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找openCV中的一个功能来帮助我制作图像蒙版.

I am looking for a function in openCV to help me make masks of images.

例如在MATLAB中:

for example in MATLAB:

B(A< 1)= 0;

B(A<1)=0;

B = zeros(size(A));

B=zeros(size(A));

B(A == 10)= c;

B(A==10)=c;

推荐答案

某些函数允许您将mask参数传递给它们.要以您描述的方式创建蒙版,我认为您是 Cmp或CmpS 是比较运算符,允许您通过与另一个数组或标量进行比较来创建掩码.例如:

Some functions allow you to pass mask arguments to them. To create masks the way you describe, I think you are after Cmp or CmpS which are comparison operators, allowing you to create masks, by comparison to another array or scalar. For example:

im = cv.LoadImageM('tree.jpg', cv.CV_LOAD_IMAGE_GRAYSCALE)
mask_im = cv.CreateImage((im.width, im.height), cv.IPL_DEPTH_8U, 1)
#Here we create a mask by using `greater than 100` as our comparison
cv.CmpS(im, 100, mask_im, cv.CV_CMP_GT)
#We set all values in im to 255, apart from those masked, cv.Set can take a mask arg.
cv.Set(im, 255, mask=mask_im)
cv.ShowImage("masked", im)
cv.WaitKey(0)

原始im:

im处理后:

这篇关于OpenCV功能类似于Matlab的“查找"功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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