我有下一个问题
我想在 openCV 中使用这个方程
X = 蓝色通道,Y = 绿色通道,Z = 红色通道
x = X / (X + Y + Z);
y = Y / (X + Y + Z);
Z = Z / (X + Y + Z);
但是当我运行我的代码时,我在 1 上有一个带有 3 个图像的窗口。
首先我提取亮度,因为我想要红色通道的色调。
有谁能够帮我?
这是我的代码:
Mat source = cv::imread("Image.bmp");
imshow("Original",source);
Mat src(source.rows, source.cols, CV_32FC3);
normalize(source,src,0,1,CV_MINMAX,CV_32FC1);
Mat Lum = Mat::zeros(src.rows, src.cols, CV_32FC1);
Mat Crom = Mat::zeros(src.rows, src.cols, CV_32FC3);
for (size_t i = 0; i < src.rows; i++)
{
for (size_t j = 0; j < src.cols; j++)
{
Vec3f pixel = src.at<Vec3f>(i, j);
float B = pixel[0];
float G = pixel[1];
float R = pixel[2];
Lum.at<float>(i, j) = ( B + G + R ) /3;
}
}
imshow("Lum",Lum);
///Codigo para la Cromancia
for (size_t i = 0; i < Lum.rows; i++)
{
for (size_t j = 0; j < Lum.cols; j++)
{
Vec3f pixel = src.at<Vec3f>(i,j);
float B = pixel[0];
float G = pixel[1];
float R = pixel[2];
Crom.at<Vec3f>(i,j)[0] = ( Lum.at<Vec3f>(i,j)[0] )/ ( Lum.at<Vec3f>(i,j)[0] + Lum.at<Vec3f>(i,j)[1] + Lum.at<Vec3f>(i,j)[2] );
Crom.at<Vec3f>(i,j)[1] = ( Lum.at<Vec3f>(i,j)[1] )/ ( Lum.at<Vec3f>(i,j)[0] + Lum.at<Vec3f>(i,j)[1] + Lum.at<Vec3f>(i,j)[2] );
Crom.at<Vec3f>(i,j)[2] = ( Lum.at<Vec3f>(i,j)[2] )/ ( Lum.at<Vec3f>(i,j)[0] + Lum.at<Vec3f>(i,j)[1] + Lum.at<Vec3f>(i,j)[2] );
}
}
imshow("Cromancia",Crom);