【发布时间】:2019-09-11 16:55:12
【问题描述】:
我想用 OpenCV 将一些 Matlab 代码翻译成 C++ 代码。我需要使用哪些功能?
对于逐元素乘法,我不知道要使用哪个函数。 例如,
cv::Mat A; cv::Mat B; cv::Mat C;
C = A + B;
//or
cv::add(A, B, C);
这是 MATLAB 代码:
% G and b are constant
% Rb, CRb and Rb_final are the images
Rb = G(CRb+b);
min3 = min(min(Rb)); % minimum in the Rb image
max3 = max(max(Rb)); % maximum in the Rb image
Rb_final = uint8(255*(Rb-min3)/(max3-min3)); % This function is to scale the image into 0 ~ 255 using maximum and minimum value in the image. And then convert the image into 8-bit unsigned image.
这是我尝试过的 OpenCV 代码:
Rb_final = uint8(255*(Rb-min3)/(max3-min3));
我通过以下代码找到最大值和最小值:
double max3, min3;
minMaxLoc(Rb, &min3, &max3);
Rb = Rb - min3;
Rb = 255 * Rb;
Rb = Rb / (max3 - min3);
我发现所有 B、G、R 频道都是这样。但是效果不如cv::convertScaleAbs(Rb, R, 255, 0);
【问题讨论】:
-
cv::add()和operator+()是等价的,请参见 the documentation。cv::multiply和*也是如此。另见here -
我通过以下代码找到最大值和最小值:double max3, min3; minMaxLoc(Rb, &min3, &max3); Rb = Rb - minb; Rb = 255 * Rb; Rb = Rb / (max3 - min3);对于所有 B、G、R 通道都是这样。但是结果不如"cv::convertScaleAbs(Rb, R, 255, 0);"
-
对不起!我现在只是编辑问题。
标签: c++ matlab opencv image-processing