- DIP - Color Space Conversion
- DIP - GrayScale Conversion OpenCV
- DIP - Introduction To OpenCV
- DIP - Open Source Libraries
- DIP - Create Zooming Effect
- DIP - Weighted Average Filter
- DIP - Laplacian Operator
- DIP - Robinson Operator
- DIP - Kirsch Operator
- DIP - Sobel Operator
- DIP - Prewitt Operator
- DIP - Understanding Convolution
- DIP - Watermark
- DIP - Eroding & Dilation
- DIP - Box Filter
- DIP - Gaussian Filter
- DIP - Image Shape Conversions
- DIP - Basic Thresholding
- DIP - Image Pyramids
- DIP - Adding Image Border
- DIP - Image Compression Technique
- DIP - Enhancing Image Sharpness
- DIP - Enhancing Image Brightness
- DIP - Enhancing Image Contrast
- DIP - Grayscale Conversion
- DIP - Image Pixels
- DIP - Image Download & Upload
- DIP - Java BufferedImage Class
- DIP - Introduction
- DIP - Home
DIP Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java DIP - Enhancing Image Brightness
In this chapter we enhance the brightness of an image by multiplying each pixel of the image with an alpha value and adding another beta value to it.
We OpenCV function convertTo that does the above operation automatically. It can be found under Mat package. Its syntax is given below −
int alpha = 2; int beta = 50; sourceImage.convertTo(destination, rtype , alpha, beta);
The parameters are described below −
Sr.No. | Parameter & Description |
---|---|
1 |
destination It is destination image. |
2 |
rtype It is desired output matrix type or, rather the depth, since the number of channels are the same as the input has. if rtype is negative, the output matrix will have the same type as the input. |
3 |
alpha It is optional scale factor. |
4 |
beta It is optional delta added to the scaled values. |
Apart from the convertTo method, there are other methods provided by the Mat class. They are described briefly −
Sr.No. | Method & Description |
---|---|
1 |
adjustROI(int dtop, int dbottom, int dleft, int dright) It adjusts a submatrix size and position within the parent matrix. |
2 |
copyTo(Mat m) It copies the matrix to another one. |
3 |
diag() It extracts a diagonal from a matrix, or creates a diagonal matrix. |
4 |
dot(Mat m) It computes a dot-product of two vectors. |
5 |
reshape(int cn) It changes the shape and/or the number of channels of a 2D matrix without copying the data. |
6 |
submat(Range rowRange, Range colRange) It extracts a rectangular sub matrix. |
Example
The following example demonstrates the use of Mat class to enhance brightness of an image −
import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.highgui.Highgui; pubpc class Main { static int width; static int height; static double alpha = 2; static double beta = 50; pubpc static void main( String[] args ) { try{ System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); Mat source = Highgui.imread("digital_image_processing.jpg",Highgui.CV_LOAD_IMAGE_COLOR); Mat destination = new Mat(source.rows(),source.cols(), source.type()); source.convertTo(destination, -1, alpha, beta); Highgui.imwrite("brightWithAlpha2Beta50.jpg", destination); } catch (Exception e) { System.out.println("error:" + e.getMessage()); } } }
Output
When you execute the given code, the following output is seen −