数字图像处理:伽马校正

#include <iostream>
#include <cmath>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
void gamma_Correct(Mat &image, Mat &result, float r)
{
	float c = 255.0 / pow(255, r);
	result = image.clone();
	int rows = image.rows, cols = image.cols;
	for (int i = 0; i < rows; i++)
	{
		for (int j = 0; j < cols; j++)
		{
			for (int k = 0; k < 3; k++)
			{
				result.at<Vec3b>(i, j)[k] = c*pow(image.at<Vec3b>(i, j)[k], r);
			}
		}
	}
}
int main()
{
	Mat image = imread("f:\\图片\\lucky.jpg");

	Mat result;
	namedWindow("原图", 0);
	namedWindow("伽马校正", 0);
	resizeWindow("原图", 500, 600);
	resizeWindow("伽马校正", 500, 600);
	for (int i = 0; i < 10; i++)
	{
		float r;
		cin >> r;
		gamma_Correct(image, result, r);
		imshow("原图", image);
		imshow("伽马校正", result);
		if(waitKey(0) == 'a') continue;
	}
	return 0;
}

通过设置不同的幂值,发现r = 0.65的时候效果不错,如下图:

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页