我需要帮助才能理解 cv::mixChannels

I need help to understand cv::mixChannels

我对 cv::mixChannels as seen here 的文档做了一些更正。但我认为参数描述需要一些更正。

例如 fromToconst int* fromToconst std::vector<int>& fromTo 的描述是相同的。

CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts,
                        const int* fromTo, size_t npairs);
CV_EXPORTS void mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst,
                        const int* fromTo, size_t npairs);
CV_EXPORTS_W void mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst,
                               const std::vector<int>& fromTo);

Parameters
    src ...
    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 . 

我在这件事上需要一些帮助。

如有任何帮助,我们将不胜感激。

为什么将 "array or vector of matrices" 更改为简单的 "array of matrices"?

关于fromTo的说法,我会尝试解构该段。

array of index pairs specifying which channels are copied and where;

它将采用 [In, Out, In, Out, In, Out, ...] 的形式。数组中的每个值都是一个整数,表示其中一个图像中的通道。这些整数和实际通道之间的映射在后面解释。

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; 

这只是重复 fromTo 数组的值在输入和输出之间交替,并且将是引用通道的数字。

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, 

这解释了编号方案。这个概念非常简单,可能被形式主义所掩盖。 src[0]是第一张输入图片,src[1]是第二张输入图片。

如果我们有两个输入图像,每个图像具有三个通道,我们将像这样命名通道:0、1、2、3、4、5。如您所见,第一张图像的通道已编号0, 1, 2 ("0 to src[0].channels()-1") 和第二个图像的通道编号为 3, 4, 5 ("src[0].channels()" (即: 3) "to src[0].channels() + src[1].channels()-1" (即: 3 + 3 - 1 = 5))

这是一种奇特的说法,我们只是依次获取每个输入并继续增加通道数,即使在移动到下一张图像时也是如此。

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 .

在一对Input/Output通道中,如果有类似-1, 3的东西,索引3代表的输出通道将被填充为零。

其实我觉得挺清楚的。在我看来,它最终可以通过两种方式进行改进:

  1. 更多健谈
  2. 更多数学

另外,我将留下 输入数组或矩阵向量

fromTo 是一个 const std::vector<Vec2i>(索引对)可能会有用,但我想这会破坏太多代码。


健谈

类似于:

fromTo:指定复制哪些通道和位置的索引数组。偶数索引表示 from 通道 src,而奇数索引表示 to 通道 dst。当偶数索引为负时,相应的 通道用零填充。在多幅图像的情况下,第二幅图像的索引跟随第一幅图像的索引,依此类推。

数学

类似于:

fromTo\[ from^{0}_{0}, to^{0}_{0}, ... from^{0}_{src[0].channels()-1}, to^{0}_{src[0].channels()-1}, ..., from^{i}_{j}, to^{i}_{j}, ... \]形式的数组,其中:

  • 来自是源图
  • 是目标图片
  • i 是源图像和目标图像在 srcdst 中的索引,
  • j是通道,从0到src[i].channels()-1

from索引为负时,后面的to通道用零填充。


只是一些随意的想法...:D