OpenCV 中的 Matlab 最小等效项

标签 matlab opencv min opencv4android

我正在寻找 min 的等价物OpenCV 中的 Matlab 函数,具有此特定功能(取自 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 张图片。我想用每个像素的最小值创建一个新图像(这两个图像),我需要存储一个 map (即 Mat 对象或类似大小的类似对象), map 的每个像素告诉我是从他的第一张图片还是第二张图片中获取最小值
(您可以将它们视为 n*m*2 图像,我想在 channel 方面取最小值,并希望能够分辨出我从哪个 channel 得到这个值)。

在 OpenCV 中是否有一种简单的方法可以做到这一点?

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

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

编辑2 - 我没有寻找获得整个矩阵的绝对最小值/最大值的解决方案 - 我想要它以像素为单位,包括一张告诉我从哪个图像中选择值的 map 。例如:
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)

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

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

关于OpenCV 中的 Matlab 最小等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47961132/

相关文章:

javascript - OpenCV.js,使用ORB和features2d构建

c - 编译 C(非 C++)OpenCV 代码时出现问题

python - 从 python 运行已编译的 MATLAB

从 Matlab 调用的 Python 子进程失败

MATLAB - 编辑框的回调执行

python - 从具有最小元素值的元组列表中提取元组的优雅方法

c++ - 不计算程序中的最低和最高成绩。 (c++) (fstream)

matlab - 如何在 MATLAB 或 Unix shell 中查看 .mat 文件?

opencv - 如果我有3D模型的2D点投影,如何找到3D仿射变换?

python - lambda 到 python 中的函数转换