- 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 Contrast
In this chapter learn how to enhance the contrast of an image using histogram equapzation.
We use the OpenCV function equapzeHist() method. It can be found under Imgproc package. Its syntax is given below −
Imgproc.equapzeHist(source, destination);
The parameters are described below −
Sr.No. | Parameter & Description |
---|---|
1 |
Source It is 8-bit single channel source image. |
2 |
Destination It is the destination image. |
Apart from the equapzeHist() method, there are other methods provided by the Imgproc class. They are described briefly −
Sr.No. | Method & Description |
---|---|
1 |
cvtColor(Mat src, Mat dst, int code, int dstCn) It converts an image from one color space to another. |
2 |
dilate(Mat src, Mat dst, Mat kernel) It dilates an image by using a specific structuring element. |
3 |
equapzeHist(Mat src, Mat dst) It equapzes the histogram of a grayscale image. |
4 |
filter2D(Mat src, Mat dst, int ddepth, Mat kernel, Point anchor, double delta) It convolves an image with the kernel. |
5 |
GaussianBlur(Mat src, Mat dst, Size ksize, double sigmaX) It blurs an image using a Gaussian filter. |
6 |
integral(Mat src, Mat sum) It calculates the integral of an image. |
Example
The following example demonstrates the use of Imgproc class to enhance contrast of an image −
import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.highgui.Highgui; import org.opencv.imgproc.Imgproc; 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("grayscale.jpg", Highgui.CV_LOAD_IMAGE_GRAYSCALE); Mat destination = new Mat(source.rows(),source.cols(),source.type()); Imgproc.equapzeHist(source, destination); Highgui.imwrite("contrast.jpg", destination); } catch (Exception e) { System.out.println("error: " + e.getMessage()); } } }
Output
When you execute the given code, the following output is seen −