学习OpenCV:滤镜系列(12)——计算模式(强光)

==============================================

版权所有:小熊不去实验室CSDN博客

==============================================


R(上)>127.5

R=R(下)+(255-R(下))*(R(上)-127.5)/127.5;

R(上)<127.5

R=R(下)-R(下)*(127.5-R(上))/127.5=(R(上)*R(下))/127.5;


#include 
#include 
#include 

using namespace cv;
using namespace std;

int R=11;

int main()
{
	Mat src = imread("D:/img/liushishi02.jpg",1);
	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(y);
		uchar* dstP=dst.ptr(y);
		for (int x=0;x127.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:/img/强光.jpg",dst);
	imwrite("D:/img/强光_蓝通道.jpg",dst1u[0]);
	imwrite("D:/img/强光_绿通道.jpg",dst1u[1]);
	imwrite("D:/img/强光_红通道.jpg",dst1u[2]);

}

原图:

学习OpenCV:滤镜系列(12)——计算模式(强光)_第1张图片

计算强光:

学习OpenCV:滤镜系列(12)——计算模式(强光)_第2张图片

红通道:

学习OpenCV:滤镜系列(12)——计算模式(强光)_第3张图片

绿通道:

学习OpenCV:滤镜系列(12)——计算模式(强光)_第4张图片

蓝通道:

学习OpenCV:滤镜系列(12)——计算模式(强光)_第5张图片

你可能感兴趣的:(滤镜,OpenCV,图像滤镜)