opencv中mixChannels的使用方法

mixChannels的使用方法


Copies specified channels from input arrays to the specified channels of output arrays.


C++: void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, const int* fromTo, size_t npairs)
C++: void mixChannels(const vector<Mat>& src, vector<Mat>& dst, const int* fromTo, size_t npairs)
Python: cv2.mixChannels(src, dst, fromTo) → None
C: void cvMixChannels(const CvArr** src, int src_count, CvArr** dst, int dst_count, const int* from_to, int pair_count)
Python: cv.MixChannels(src, dst, fromTo) → None
Parameters:
src – input array or vector of matricesl; all of the matrices must have the same size and the same depth.
nsrcs – number of matrices in src.
dst – output array or vector of matrices; all the matrices must be allocated; their size and depth must be the same as in src[0].
ndsts – number of matrices in dst.
fromTo – array of index pairs specifying which channels are copied and where; fromTo[k*2] is a 0-based index of the input channel in src, fromTo[k*2+1] is an index of the output channel in dst; the continuous channel numbering is used: the first input image channels are indexed from 0 to src[0].channels()-1, the second input image channels are indexed from src[0].channels() to src[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image channels; as a special case, when fromTo[k*2] is negative, the corresponding output channel is filled with zero .
npairs – number of index pairs in fromTo.
The functions mixChannels provide an advanced mechanism for shuffling image channels.

split() and merge() and some forms of cvtColor() are partial cases of mixChannels .

In the example below, the code splits a 4-channel RGBA image into a 3-channel BGR (with R and B channels swapped) and a separate alpha-channel image:


Mat rgba( 100, 100, CV_8UC4, Scalar(1,2,3,4) );
Mat bgr( rgba.rows, rgba.cols, CV_8UC3 );
Mat alpha( rgba.rows, rgba.cols, CV_8UC1 );

// forming an array of matrices is a quite efficient operation,
// because the matrix data is not copied, only the headers
Mat out[] = { bgr, alpha };
// rgba[0] -> bgr[2], rgba[1] -> bgr[1],
// rgba[2] -> bgr[0], rgba[3] -> alpha[0]
int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
mixChannels( &rgba, 1, out, 2, from_to, 4 );

Note

 

Unlike many other new-style C++ functions in OpenCV (see the introduction section and Mat::create() ), mixChannels requires the output arrays to be pre-allocated before calling the function.



广告阶段:
本人开了淘宝店,欢迎你惠顾,价格优惠,购买是说明来于csdn,将给你最实惠价格。

店名:小时代乐园

承诺:本店以诚信求生存,以质量求人员,货真价实,绝无欺骗行为。
简介:本店主要营销大品牌、安全有保障的商品,提供儿童益智娱乐品牌宝贝,让你全方位精心打扮,提升体验度和品味,让你买得开心,用得放心,穿得舒心,听得暖心。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值