当我使用matlab中的“显示”功能显示图像的像素值(转换为灰度的RGB图像)时,我发现像素值小于1(所有值都在0和1之间)。而当我在opencv中做同样的事情时,我的价值也越来越高。为什么价值观会发生变化? 打开CV代码和matlab代码如下:
for (int i = 0; i < img1.rows; i++)
{
for (int j = 0; j < img1.cols; j++)
{
cout << (unsigned int)img1.at<uchar>(i, j) << endl;
}
}
Matlab code:
gI=rgb2gray(I);
imshow(gI);
答案 0 :(得分:1)
Sorry to disappoint you. No one guarantees that the conversion of RGB to gray-scale will yield the same result. There are 2 reasons
0.299f*RED + 0.587f*GREEN + 0.114f*BLUE
Here) while Matlab uses another method (0.2989*RED + 0.587*GREEN + 0.1140*BLUE. Here). Note the difference between openCV 0.299 and Matlabs 0.2989.
More information can be found in this answer (here)答案 1 :(得分:1)
我的垫子是8UC3型。如何转换归一化的double值 MATLAB到8UC3?仅乘以255就足够了吗?
在8UC3
字节的情况下,然后是足以乘以255.它们被设计为以这种方式工作。 8UC 3 中的 3 表示三个频道红色,绿色和蓝色 < / p>
无论如何,在0 to 255
范围值和0.0 to 1.0
范围值之间进行转换
//Psuedo-code formula:
col_val = 210; //range 0-255
normalised = col_val / 255; //always divide by 255 for a normalised to "1.0" version
normal_reverse_to255 = normalised * 255; //make it back into "0 to 255" range
预期结果:
col_val = 210 //original value before normalised
标准化 = 0.8235 //...294117647058 etc etc //after normalised to 0.0 to 1.0 range
normal_reverse_to255 = 210; //multiply result is same as original value
希望这对你有所帮助。
编辑:
我刚刚意识到你正在使用gI=rgb2gray(I);
来获取灰度图像。
cvtColor(src,dst,CV_GRAY2RGB);
被this answer 劫持latitude_new = atan(sin(latitude)/fabs(cos(latitude)))