OpenCV_12计算模式(强光)

一,原图:

二,代码:

//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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值