一,原图:
二,代码:
//12计算模式(强光)
void CalculationMode()
{
Mat src = imread("D:\\test\\12.jpg");
imshow("src", src);
int width = src.cols;
int heigh = src.rows;
Mat img;
src.copyTo(img);
Mat dst(img.size(), CV_8UC3);
Mat dst1u[3];
float tmp, r;
for (int y = 0; y<heigh; y++)
{
uchar* imgP = img.ptr<uchar>(y);
uchar* dstP = dst.ptr<uchar>(y);
for (int x = 0; x<width; x++)
{
r = (float)imgP[3 * x];
if (r>127.5)
tmp = r + (255 - r)*(r - 127.5) / 127.5;
else
tmp = r*r / 127.5;
tmp = tmp>255 ? 255 : tmp;
tmp = tmp<0 ? 0 : tmp;
dstP[3 * x] = (uchar)(tmp);
r = (float)imgP[3 * x + 1];
if (r>127.5)
tmp = r + (255 - r)*(r - 127.5) / 127.5;
else
tmp = r*r / 127.5;
tmp = tmp>255 ? 255 : tmp;
tmp = tmp<0 ? 0 : tmp;
dstP[3 * x + 1] = (uchar)(tmp);
r = (float)imgP[3 * x + 2];
if (r>127.5)
tmp = r + (255 - r)*(r - 127.5) / 127.5;
else
tmp = r*r / 127.5;
tmp = tmp>255 ? 255 : tmp;
tmp = tmp<0 ? 0 : tmp;
dstP[3 * x + 2] = (uchar)(tmp);
}
}
imshow("强光", dst);
split(dst, dst1u);
imshow("绿通道强光", dst1u[1]);
waitKey();
imwrite("D://强光.jpg", dst);
imwrite("D://强光_蓝通道.jpg", dst1u[0]);
imwrite("D://强光_绿通道.jpg", dst1u[1]);
imwrite("D://强光_红通道.jpg", dst1u[2]);
}
//-----开始------
void COpenCVLearningDlg::OnBnClickedStartButton()
{
CalculationMode();
}
三,结果:
欢迎扫码关注我的微信公众号
原文地址:https://blog.youkuaiyun.com/sangni007/column/info/stylizefliter