思路:如果是蓝边,让b>statution&&b-g>thd则认为是蓝边,倒时有冲突景再细分
因为调整完的图像会黑一块正常的一块,我们就需要在黑的那块乘上一个gain,但是如果r&g差不多的话需要考虑一下,避免误抬高,thd就是gain。
// 计算蓝色通道和绿色通道的差值
cv::Mat diff_g_b;
cv::Mat diff_g_b_1;
cv::Mat diff_g_r_1;
uchar b_thd=160;
uchar diff_thd = 70;
float diff_gr_thd = 1.3;
float thd=1;
cv::subtract(channels[0], channels[1], diff_g_b);
cv::split(image, channels);
for (int i = 0; i < image1.rows; ++i)
{
for (int j = 0; j < image1.cols; ++j)
{
if (channels1[0].at<uchar>(i, j)> b_thd)
{
if(channels1[0].at<uchar>(i, j)- channels1[1].at<uchar>(i, j)>diff_thd)
{
blue_pixel_org = channels1[0].at<uchar>(i, j);
green_pixel_org = channels1[1].at<uchar>(i, j);
red_pixel_org = channels1[2].at<uchar>(i, j);
float result3 = static_cast<float>(blue_pixel_org);
float result4 = static_cast<float>(green_pixel_org);
float result5 = static_cast<float>(red_pixel_org);
float green_blude_pixel_add1 = blue_pixel_org + green_pixel_org;
channels1[0].at<uchar>(i, j) = green_pixel_org - red_pixel_org + channels1[1].at<uchar>(i, j);
if(result4/ result5> diff_gr_thd)
{
float result2 = (green_blude_pixel_add1) /(static_cast<float>(channels1[0].at<uchar>(i, j))+ static_cast<float>(channels1[1].at<uchar>(i, j)));
channels1[0].at<uchar>(i, j) = channels1[0].at<uchar>(i, j) * result2*thd;
channels1[1].at<uchar>(i, j) = channels1[1].at<uchar>(i, j) * result2*thd;
channels1[2].at<uchar>(i, j) = channels1[2].at<uchar>(i, j) * result2*thd;
}
}
}
}
}
cv::subtract(channels1[0], channels1[1], diff_g_b_1);
// 将通道合并回去
cv::merge(channels1, 3, image1);