OpenCV 中的 Matlab 最小等效值

Matlab min equivalent in OpenCV

我正在寻找 OpenCV 中 Matlab 的 min 函数的等效项,具有此特定功能(取自 the official Matlab documentation):

[M,I] = min(___) finds the indices of the minimum values of A and returns them in output vector I, using any of the input arguments in the previous syntaxes. If the minimum value occurs more than once, then min returns the index corresponding to the first occurrence.

在我的具体情况下,我有 2 张图片。我想用每个像素的最小值创建一个新图像(wrt 那些 2 个图像),我需要存储一个地图(即 Mat 对象或类似大小的东西),其中每个像素map 告诉我最小值是取自第一张还是第二张图像 (你可以将它们视为 n*m*2 图像,我想在其中按通道取最小值,并希望能够分辨出我从哪个通道获得了这个值)。

在 OpenCV 中有没有简单的方法来做到这一点?

顺便说一句,它适用于 Android 应用程序,因此 Java 答案优于 C++。谢谢。

编辑:我可以想到一些循环解决方案,但我需要我的解决方案尽可能高效,所以我想看看是否有一些内置函数

EDIT2 - 我没有寻找获得 whole 矩阵的绝对 min/max 值的解决方案 -我希望它是像素级的,包括一张地图,告诉我从哪个图像中选择了值。例如:

A = [1 2 ;
     3 4 ]
B = [5 6 ;
     1 2 ]

-->
min(A,B) = [1 2 ;
            1 2 ]
// these are the actual values ^


minInd(A,B) = [1 1 ;
               2 2 ]
// these are the indices ^ where 1 means it was taken from A, and 2 means it was taken from B

编辑:我原来的回答没用

怎么样

MatExpr min(const Mat& a, const Mat& b)

来自 post。如果您从原始图像 ABC=min(A,B) 开始,那么您可以定义 D=A-C。如果 D(i,j)==0,则该值源自 A。如果 D(i,j)>0,则像素值来自 B

如果 AB 持有浮点数而不是整数,那么您当然必须以较小的公差进行比较。