opencv的mask

来源:互联网 发布:淘宝vip客服 编辑:程序博客网 时间:2024/05/29 14:05

opencv的mask:

转载地址:http://blog.csdn.net/moc062066/article/details/6548450

opencv 里面很多函数都是会带有一个mask 参数的,很多同学都不知道它到底有什么用,好像在实际运用中忽略它也没有什么问题(opencv设计师设计它的时候默认就是可以忽略的)。详细分析一个常用函数cvcopy里面的mask ,希望可以给大家一点点指引。


void cvCopy(const CvArr* src, CvArr* dst, const CvArr* mask=NULL);


src The source array

//源数组,要复制谁??from whom?

//插两句题外话,opencv里面提到的数组不是通常意义上的数组,它是矩阵、图像等结构体……


dst The destination array

//目标数组,复制以后的内容给谁?? to whom? 

mask

——下面这就是重点。鄙人认为很多人都没有深刻理解这个mask的作用 ——

Operation mask, 8-bit single channel array; specifies elements of the destination array to
be changed

//掩码操作,mask是一个8位单通道的数组;mask指定了目标数组(dst)中那些元素是可以改变的


The function copies selected elements from an input array to an output array:
dst(I) = src(I) if mask(I) = 0.

//该函数把输入数组(src数组)中选中的元素(可以认为是做了标记的,不过这些标志是谁来做的呢??对,就是mask)

 

dst(I) = src(I) if mask(I) != 0.

就是说,如果mask不是NULL,也就是说mask是一个数组,并且是一个和dst or src大小完全一致的数组。


遍历src的每一个元素,

(1)在位置i时候如果mask对应的值为不为0,那么把src (i) 的值复制给dst (i) 

(2)如果mask(i) 为0,那么不管src(i)是什么,dst(i)都设置为0.


举例说明,这里不举太复杂的就来一个一维的就够啦。

 

 

 

If any of the passed arrays is of IplImage type, then its ROI and COI fields are used. Both
arrays must have the same type, the same number of dimensions, and the same size. The function
can also copy sparse arrays (mask is not supported in this case).

//如果传递给src的数组是图像类型的,那么将使用ROI或者COI。src数组和dst数组必须具有相同的数据类型、一致的数组维数、一样的大小。该函数也可以用于拷贝稀疏矩阵(但是此种情况下,mask不起作用)。


掩码就是:不为0的时候就可以操作(具体是什么操作就看具体的函数了)、为0就掩盖住了无法操作。

 

补充一点 :mask = NULL  意思就是没有模板、不使用掩码操作,函数该干啥就干啥……