[OpenCV4] cv :: merge()

在对图像做傅里叶变换的时候,看到了一段代码

    Mat padded;                            //expand input image to optimal size
    int m = getOptimalDFTSize( I.rows );
    int n = getOptimalDFTSize( I.cols ); // on the border add zero values
    copyMakeBorder(I, padded, 0, m - I.rows, 0, n - I.cols, BORDER_CONSTANT, Scalar::all(0));
    Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};
    Mat complexI;
    merge(planes, 2, complexI);         // Add to the expanded another plane with zeros
    dft(complexI, complexI);       

在进行离散傅里叶变换(dft(complexI, complexI))之前,进行了merge操作

merge(planes, 2, complexI);         // Add to the expanded another plane with zeros

那么这一行究竟在干什么呢?

从形式上看,是将Mat数组中的两个单通道float类型的图像归并到一个Mat对象complexI中

得到的Mat对象complexI 便是一个两通道的图像了,且每个通道均为float类型(CV_32F)

1.解释

1.1 头文件

 #include <opencv2/core.hpp> 

 

1.2 函数原型

三个参数:

1.2.1 const Mat* mv 

input array of matrices to be merged; all the matrices in mv must have the same size and the same depth.

这里使用了const ClassType * pointerName 的形式,即传入的Mat类型的指针不能修改这个图像本身的内容(但是可以用其他的方式修改),这里通常传入的是待合并的图像数组的首地址。传入的图像必须有相同的深度和大小。

 

1.2.2 size_t count

number of input matrices when mv is a plain C array; it must be greater than zero.

(参考博客:size_t 解释) 一个uint型的合并之后的图像的通道数,必须大于0

 

1.2.3 OutputArray

output array of the same size and the same depth as mv[0]; The number of channels will be equal to the parameter count.

dst 输出的图像数组(Mat对象或者其他类型),图像的最终channel与传入的size_t count相同,图像的尺寸与传入数组中的第一个单通道图像相同

 

1.3 功能解释

官网解释:Creates one multi-channel array out of several single-channel ones.

将多个单通道图像合并为一个多通道的图像

The function cv::merge merges several arrays to make a single multi-channel array. That is, each element of the output array will be a concatenation of the elements of the input arrays, where elements of i-th input array are treated as mv[i].channels()-element vectors.

merge函数是有序的,它将传入的单通道的图像按照次序进行串联,第i个输入的图像将被作为合并后图像的第i个通道

 

2.实例

    Mat m1 = (Mat_<uchar>(2,2) << 1,4,7,10);
    Mat m2 = (Mat_<uchar>(2,2) << 2,5,8,11);
    Mat m3 = (Mat_<uchar>(2,2) << 3,6,9,12);
    Mat channels[3] = {m1, m2, m3};
    Mat m;
    merge(channels, 3, m);
    /*
    m =
    [  1,   2,   3,   4,   5,   6;
       7,   8,   9,  10,  11,  12]
    m.channels() = 3
    */

上面的代码生成了三个单通道的大小为2*2的Mat_对象

然后将这三个Mat_对象构成一个数组channels

使用函数merge将这三个图像合成一个三通道的图像m

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值