我已将一张图像分成了三个独立的颜色通道——蓝色、绿色和红色。我想对每个通道进行归一化处理,使其与图像的强度相匹配,其中强度=(红色+蓝色+绿色)/3。请注意,我试图制作一个由三个颜色通道中的一个组成的图像,它被图像的强度除以,其中强度由上述方程式描述。
我是OpenCV的新手,我不认为我的做法是正确的;当这些图像被显示时,所有像素都显示为黑色。
我是OpenCV的新手(我已经完成了文档附带的教程,但仅此而已),如果您能给我一些建议来解决这个归一化问题,那将非常有帮助。
谢谢! 以下是我的尝试:
谢谢! 以下是我的尝试:
int main(int argc, char** argv){
Mat sourceImage, I;
const char* redWindow = "Red Color Channel";
const char* greenWindow = "Green Color Channel";
const char* blueWindow = "Blue Color Channel";
if(argc != 2)
{
cout << "Incorrect number of arguments" << endl;
}
/* Load the image */
sourceImage = imread(argv[1], 1);
if(!sourceImage.data)
{
cout << "Image failed to load" << endl;
}
/* First, we have to allocate the new channels */
Mat r(sourceImage.rows, sourceImage.cols, CV_8UC1);
Mat b(sourceImage.rows, sourceImage.cols, CV_8UC1);
Mat g(sourceImage.rows, sourceImage.cols, CV_8UC1);
/* Now we put these into a matrix */
Mat out[] = {b, g, r};
/* Split the image into the three color channels */
split(sourceImage, out);
/* I = (r + b + g)/3 */
add(b, g, I);
add(I, r, I);
I = I/3;
Mat red = r/I;
Mat blue = b/I;
Mat green = g/I;
/* Create the windows */
namedWindow(blueWindow, 0);
namedWindow(greenWindow, 0);
namedWindow(redWindow, 0);
/* Show the images */
imshow(blueWindow, blue);
imshow(greenWindow, green);
imshow(redWindow, red);
waitKey(0);
return 0;
}