- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Change Contrast in OpenCV using C++?
Changing brightness and contrast are frequent editing effect in image processing.Here, we will learn how to change the contrast of images. Contrast controls the sharpness of the image. Higher the contrast the sharper the image, lower the contrast the smother the image.
Changing the contrast means increasing the weight of the pixels. More the contrast, sharper the image is. To change the contrast, multiply the pixel values with some constant. For example, if multiply all the pixel values of an image by 2, then the pixel's value will be doubled, and the image will look sharper.
The following program demonstrates how to change the contrast of an image in OpenCV.
Example
#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); }
Output
- Related Articles
- How to change the contrast and brightness of an image using OpenCV in Python?
- How to alter the contrast of an image using Java OpenCV library?
- Altering the brightness and contrast of an image using JavaFX and OpenCV
- How to adjust the contrast of an image using contrast() function in Node Jimp?
- How to change Pixel values using Direct Access Method in OpenCV?
- How to change Pixel Values using 'at' Method in OpenCV?
- How to change the brightness of an image in OpenCV using C++?
- How to change the color spaces of an image using Java OpenCV library?
- How can we change the resolution of a video in OpenCV using C++?
- How to change the size of an image and add a border in OpenCV using C++?
- Adjusting the Image Contrast using CSS3
- How to draw polylines in OpenCV using Java?
- How to blend to images using OpenCV Java?
- PyTorch – Randomly change the brightness, contrast, saturation and hue of an image
- How to draw a line in OpenCV using Java?

Advertisements