==============================================
版权所有: 小熊不去实验室 CSDN博客
==============================================
载入选区就是在图像中选取高亮的部分
R=min(127.5,avg)
if(pix[x,y]>R)
dst[x,y]=255;
else
dst[x,y]=255;
#include #include #include using namespace cv;using namespace std;int R=11;int main(){Mat src = imread("D:/img/arrow03.jpg",1);imshow("src",src);int width=src.cols;int heigh=src.rows;Mat img(heigh/2,width/2,CV_8UC3);resize(src,img,img.size());Scalar avg=mean(src);Mat dst(img.size(),CV_8UC3);Mat mask1u[3];float avg0 = avg[0]*2>127.5 ? 127.5:avg[0]*2;float avg1 = avg[1]*2>127.5 ? 127.5:avg[1]*2;float avg2 = avg[2]*2>127.5 ? 127.5:avg[2]*2;float tmp,r;for (int y=0;y(y);uchar* dstP=dst.ptr(y);for (int x=0;xavg0)tmp = 255;elsetmp = 0;dstP[3*x]=(uchar)(tmp);r = (float)imgP[3*x+1];if(r>avg1)tmp = 255;elsetmp = 0;dstP[3*x+1]=(uchar)(tmp);r = (float)imgP[3*x+2];if(r>avg2)tmp = 255;elsetmp = 0;dstP[3*x+2]=(uchar)(tmp);}}imshow("载入选区",dst);split(dst,mask1u);imshow("蓝通道选区",mask1u[0]);imshow("绿通道选区",mask1u[1]);imshow("红通道选区",mask1u[2]);waitKey(); //imwrite("D:/img/强光.jpg",dst); imwrite("D:/img/蓝通道选区.jpg",mask1u[0]); imwrite("D:/img/蓝通道选区.jpg",mask1u[1]); imwrite("D:/img/蓝通道选区.jpg",mask1u[2]);}
原图:
载入选区:
红通道: 绿通道:
蓝通道:
本文转载自:CSDN博客
欢迎加入我爱机器学习QQ14群:336582044
微信扫一扫,关注我爱机器学习公众号