[opencv]白平衡算法中的灰度世界法,改善图像发红发蓝发绿的现象

#include<iostream>
#include <opencv2/opencv.hpp>
#include <math.h> using namespace cv;
using namespace std; ////该代码实现白平衡算法中的灰度世界法,能有效改善图像发红发蓝发绿的现象; #include <opencv2/opencv.hpp>
using namespace cv; int main()
{
Mat g_srcImage,dstImage;
vector<Mat> g_vChannels;
g_srcImage = imread("/home/leoxae/KeekoRobot/TestPic/multCards/58.png");
imshow("原图",g_srcImage);
//waitKey(0); //分离通道
split(g_srcImage,g_vChannels);
Mat imageBlueChannel = g_vChannels.at(0);
Mat imageGreenChannel = g_vChannels.at(1);
Mat imageRedChannel = g_vChannels.at(2); double imageBlueChannelAvg=0;
double imageGreenChannelAvg=0;
double imageRedChannelAvg=0; //求各通道的平均值
imageBlueChannelAvg = mean(imageBlueChannel)[0];
imageGreenChannelAvg = mean(imageGreenChannel)[0];
imageRedChannelAvg = mean(imageRedChannel)[0]; //求出个通道所占增益
double K = (imageRedChannelAvg+imageGreenChannelAvg+imageRedChannelAvg)/3;
double Kb = K/imageBlueChannelAvg;
double Kg = K/imageGreenChannelAvg;
double Kr = K/imageRedChannelAvg; //更新白平衡后的各通道BGR值
addWeighted(imageBlueChannel,Kb,0,0,0,imageBlueChannel);
addWeighted(imageGreenChannel,Kg,0,0,0,imageGreenChannel);
addWeighted(imageRedChannel,Kr,0,0,0,imageRedChannel); merge(g_vChannels,dstImage);//图像各通道合并
imshow("白平衡后图",dstImage);
imwrite("/home/leoxae/KeekoRobot/TestPic/multCards/test.png",dstImage);
waitKey(0);
return 0;
}

运行结果:[opencv]白平衡算法中的灰度世界法,改善图像发红发蓝发绿的现象

上一篇:在iis中设置文件下载而不是在浏览器上打开


下一篇:MugLife静态照片变3D动画算法研究