我有下一个问题
我想在openCV中使用这个方程式
X =蓝色通道,Y =绿色通道,Z =红色通道
x = X / (X + Y + Z);
y = Y / (X + Y + Z);
Z = Z / (X + Y + Z);
但是,当我运行代码时,我的窗口上有3张图片,上面有1张图片。
首先,我提取亮度是因为我想要红色通道的柔韧性。
有人可以帮助我吗?
这是我的代码:
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);