改变图像对比度

#include
#include

using namespace std;
using namespace cv;

int main()
{
	Mat img;
	Mat img1;
	Mat dst;

    img = imread("/home/l/桌面/opencv/1.jpg");
    //显示图像(窗口名,Mat对象)
	imshow("img",img);
	//掩膜操作

	/*
	int cols = (src.cols-1) * src.channels();
	int offsetx = src.channels();
	int rows = src.rows;
	dst = Mat::zeros(src.size(), src.type());
	for (int row = 1; row < (rows - 1); row++) {
		const uchar* previous = src.ptr(row - 1);
		const uchar* current = src.ptr(row);
		const uchar* next = src.ptr(row + 1);
		uchar* output = dst.ptr(row);
		for (int col = offsetx; col < cols; col++) {
			output[col] = saturate_cast(5 * current[col] - (current[col- offsetx] + current[col+ offsetx] + previous[col] + next[col]));
		}
	}
	*/
	double t = getTickCount();
	//定义掩膜
	Mat kernel = (Mat_(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
	//img,dst是Mat类型变量,img.depth表示位图深度有32,4,8
	filter2D(img, dst, img.depth(), kernel);
	double timeconsume = (getTickCount() - t) / getTickFrequency();
	printf("timeconsume %.2f\n", timeconsume);
	
	imshow("contrast image demo", dst);
 
	waitKey(0);

    return 0;
}

效果图

改变图像对比度_第1张图片

 

你可能感兴趣的:(opencv学习记录,opencv,计算机视觉,人工智能)