图像处理算子是带有一幅或多幅输入图像、产生一幅输出图像的函数。
图像变换可分为以下两种:点算子(像素变换)邻域算子
图像增强和亮度调整属于像素变换范畴常见变换方法是:
其中 i 和 j属于行和列
#define WIN_NAME "输出图像" Mat srcImage; Mat dstImage; int contrast = 20, bright = 20; void onChange(int, void*) { for (int i = 0; i < srcImage.rows; i++) { for (int j = 0; j < srcImage.cols; j++) { //也可以用for循环 dstImage.at<Vec3b>(i, j)[0] = saturate_cast<uchar>(srcImage.at<Vec3b>(i, j)[0] * contrast*0.01 + bright); dstImage.at<Vec3b>(i, j)[1] = saturate_cast<uchar>(srcImage.at<Vec3b>(i, j)[1] * contrast*0.01 + bright); dstImage.at<Vec3b>(i, j)[2] = saturate_cast<uchar>(srcImage.at<Vec3b>(i, j)[2] * contrast*0.01 + bright); } } // srcImage.convertTo(dstImage, -1, 0.01, 20); imshow("原图", srcImage); imshow(WIN_NAME, dstImage); } void main() { srcImage = imread("E:\欣奕华\项目\OPENCV\ContrastBright\ConBrightness\1.jpg", 1); dstImage.create(srcImage.size(), srcImage.type()); namedWindow(WIN_NAME, WINDOW_AUTOSIZE); createTrackbar("对比度", WIN_NAME, &contrast, 200, onChange, 0); createTrackbar("亮 度", WIN_NAME, &bright, 200, onChange, 0); onChange(contrast, 0);//回调函数初始化 onChange(bright, 0); waitKey(); }