OpenCV使用filter2D实现图像对比度提升

一、概述

  案例:使用filter2d+掩码矩阵来实现图像对比度提升。

  主要关注filter2d的前三个参数:

  1.第一个参数:原始图像

  2.第二个参数:卷积后的图像

  3.第三个参数:图形深度,要和原图像相同

二、效果图(看人物图像,左边人物比较模糊,提升对比度后突现由朦胧变为清晰)

  

 

 

三、示例代码

#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>

using namespace cv;
using namespace std;

int main(int argc, char const *argv[])
{
	Mat src,dst;
	src = imread("girl.jpg");
	if(!src.data){
		cout << "count not load image ..."<<endl;
		return -1;
	}
	imshow("src",src);

	double t = getTickCount();
	//定义一个增强对比度的卷积核
	Mat kernel = (Mat_<char>(3,3)<<0, -1, 0, -1, 5, -1, 0, -1, 0);
	//进行掩码卷积操作
	filter2D(src,dst,src.depth(),kernel);
	double timeconsume = (getTickCount()-t)/getTickFrequency();
	cout <<"time timeconsume%f"<<timeconsume<<endl;
	imshow("dst",dst);
	waitKey(0);
	return 0;
}

  

posted on 2021-10-08 14:14  飘杨......  阅读(463)  评论(0编辑  收藏  举报