OpenCV无法获得正确的Mat最大值和最小值
OpenCV can not get the right max and min values of Mat
我试图找到 Mat 的最大值和最小值,但我无法得到正确的答案。我在 MATLAB 中得到了正确的最大值和最小值,即 maxValue==2.2222 和 minValue==0.0810810。但是我在 OpenCV 中得到了其他结果 maxValue==8.988e+307 和 minValue==0.0232549 OpenCV.In,我使用了两种方法,std::max_element() 和 minMaxLoc(),并得到了相同的结果。我的代码(OpenCV):
#include <iostream>
#include <string>
#include <math.h>
#include <cv.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#define PI 3.1415926
using namespace std;
using namespace cv;
int main()
{
Mat img=imread("test.jpg");
if(!img.data)
{
cout<<"Error:Reading image!"<<endl;
}
img.convertTo(img,CV_64FC3);
vector<Mat> rgb;
split( img, rgb);
Mat B=rgb[0];
Mat G=rgb[1];
Mat R=rgb[2];
Mat x,X,y,Y;
divide(R,G,x,1);
divide(B,G,y,1);
log(x,X);
log(y,Y);
Mat projectedPoint;
projectedPoint=X.mul(cos(PI))+Y.mul(sin(PI));
Mat imgGrey;
exp(projectedPoint,imgGrey);
//method 1;
cout<<"max_element=="<<*max_element(imgGrey.begin<double>(),imgGrey.end<double>())<<endl;
//method 2;
double imgGreyMin=0;
double imgGreyMax=0;
minMaxLoc(imgGrey,&imgGreyMin,&imgGreyMax,NULL,NULL);
cout<<"minValue=="<<imgGreyMin<<" maxValue=="<<imgGreyMax<<endl;
waitKey(0);
return 0;
}
马特实验室:
clc;
clear;
format long;
img=imread('test.jpg');
img=im2double(img);
R=img(:,:,1);
G=img(:,:,2);
B=img(:,:,3);
X=log(R./G);
Y=log(B./G);
W=size(X,1);
L=size(X,2);
projectedPoint=ones(W,L);
projectedPoint=X*cosd(180)+Y*sind(180);
imgGrey=exp(projectedPoint);
minValue=min(min(imgGrey));
maxValue=max(max(imgGrey));
我的猜测是问题不在于minMaxLoc,即当你的函数达到这一点时,imgGrey确实有这么大的值。如果 G 像素之一等于零,则可能会发生这种情况(我猜 MATLAB 对这种情况的处理方式不同)。
附带说明一下,我不太明白这条线的用途:
projectedPoint=X.mul(cos(PI))+Y.mul(sin(PI));
cos(PI) 是 -1. sin(PI) 是 0。你可以写:
projectedPoint = -X;
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 使用指针从C++中的数组中获取最大值
- 如何将这个C++哈希表转换为动态扩展和收缩,而不是使用硬设置的最大值
- 如何创建一个函数来计算并返回平均值、最大值和最小值
- 在二维数组中查找最小值和最大值?
- 整数溢出,最大值为 pow(10,19)
- 以C++递归方式查找向量中的最大值
- C++ - 如何在结构向量中找到结构体一个成员的最大值?
- 查找数组中第一个最小值和最后一个最大值元素之间的算术平均值
- C++ 函数,用于查找传入的 N 个数字的平均值、总和、最小值和最大值
- 我的 If Else 语句无法在向量 (C++) 中提供最大值
- 如何使用可变参数模板类使用模板元编程获得最大值
- C++不同的最小最大值实现
- Vec3b:r/g/b 颜色的最大值为 254,而不是 255
- CUDA - 将 float3 数组的 (x,y,z) 分量的最小值/最大值分开?
- 是否可以将无符号 int 的最大值转换为 int 并将结果转换为 -1?
- 如何获得CV :: MAT至2 x 2最大值平均值
- OpenCV无法获得正确的Mat最大值和最小值
- 使用最小值和最大值缩放 Mat 中的每个单元格
- 求cv::Mat的最大值