安徒生童话好词低照度图像增强代码低照度图像增强代码
代码
// An highlighted block
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <stdio.h>
//#include <cv.h>
//#include<highgui.h>
using namespace cv;
using namespace std;
//图像的三个颜⾊通道
#define BLUE0
#define GREEN1
不灭的火焰
#define RED2
#ifndef SCREEN_XY
#define SCREEN_XY(x, y)(255-((255-(x))*(255-(y))>>8))//将新的图层与原图做滤⾊混合//x为原始图像像素值,y为新图层的像素值
#endif
int main()
{
char imgfile[256]="E:\\新桌⾯\\新建⽂件夹 (4)\\Project1\\Low Light\\09.png";//载⼊需要增强图像 Mat src =imread(imgfile);//载⼊图像需要是三通道彩⾊图像
imshow("待增强图像", src);
int size = ls * ws;//获取原图像的⼤⼩
uchar r =0, g =0, b =0, g_alpha =0;//定义参数初始值
uchar *pSrcData = src.data;//获取图图像的像素值
for(int i =0; i < size; i++, pSrcData +=3)//
{
//将绿⾊通道反⾊,与b、g、r通道分别相乘,得到新的图层颜⾊元宵简笔画
g_alpha =255- pSrcData[GREEN];//将绿⾊通道反⾊手机上网速度慢
b = pSrcData[BLUE]* g_alpha >>8;
g = pSrcData[GREEN]* g_alpha >>8;
r = pSrcData[RED]* g_alpha >>8;
//将上个步骤得到的新图层,与原始图做滤⾊混合,即执⾏f(a,b)=1-(1-a)*(1-b)的操作
pSrcData[BLUE]=SCREEN_XY(pSrcData[BLUE], b);//九年级英语书
pSrcData[GREEN]=SCREEN_XY(pSrcData[GREEN], g);
pSrcData[RED]=SCREEN_XY(pSrcData[RED], r);
//如果发现使⽤⼀次照度增强后,图⽚仍然偏暗,再运⾏⼀次上述代码
指数投资//如果觉得合适,就只增强⼀次即可
g_alpha =255- pSrcData[GREEN];
b = pSrcData[BLUE]* g_alpha >>8;
g = pSrcData[GREEN]* g_alpha >>8;
r = pSrcData[RED]* g_alpha >>8;
pSrcData[BLUE]=SCREEN_XY(pSrcData[BLUE], b);
pSrcData[GREEN]=SCREEN_XY(pSrcData[GREEN], g);
pSrcData[RED]=SCREEN_XY(pSrcData[RED], r);猫能不能吃火腿肠
}
spa水疗imshow("增强后的图像", src);
imwrite("test09.png",src);
waitKey();
return0;
}