如何使用 C++ 在 OpenCV 中更改对比度?
在图像处理中,经常会使用更改亮度和对比度的方法进行编辑。下面,我将学习如何更改图像的对比度。对比度控制图像的清晰度。对比度越高,图像越清晰,对比度越低,图像越柔和。
更改对比度即是指增加像素的权重。对比度越高,图像越清晰。要更改对比度,可以将像素值乘以某个常数。例如,如果将图像中所有像素的值乘以 2,则像素值将加倍,且图像的清晰度将提高。
以下程序演示了如何在 OpenCV 中更改图像的对比度。
示例
#include<iostream>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main() {
Mat original;//Declaring a matrix to load the original image//
Mat contrast;//Declaring a matrix to load the image after changing the brightness//
namedWindow("Original");//Declaring window to show the original image//
namedWindow("Contrast");//Declaring window for edited image//
original = imread("mountain.jpg");//loading the image
original.convertTo(contrast, -1, 2, 0);//changing contrast//
imshow("Original", original);//showing original image//
imshow("Contrast", contrast);//showing edited image//
waitKey(0);//wait for keystroke//
return(0);
}输出

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP