【原文:http://blog.csdn.net/yangtrees/article/details/9206967】
==============================================
版权所有:小熊不去实验室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 <math.h>
- #include <opencv/cv.h>
- #include <opencv/highgui.h>
- 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<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:/img/强光.jpg",dst);
- imwrite("D:/img/强光_蓝通道.jpg",dst1u[0]);
- imwrite("D:/img/强光_绿通道.jpg",dst1u[1]);
- imwrite("D:/img/强光_红通道.jpg",dst1u[2]);
- }
原图:
计算强光:
红通道:
绿通道:
蓝通道: