In this packet, we will be doing histogram equalization in low contrast images to improve its contrast, using Python and OpenCV library.
Histogram equalization is a very basic and useful image processing technique. It is basically used to improve the contrast of images. It does this by effectively spreading out the intensity of pixels from dense areas in the histogram over the entire range of pixels, that is, from 0 to 255. An example of spreading the histogram of an image is as shown below:
Here, originally the pixels in the image are densely populated in the range 100 to 175. But after applying histogram equalization, the intensities are spread out over the entire range giving drastic improvements over images.
This task is implemented using the OpenCV library in Python. The code for this is as shown below:
def histogram_equilizer(image): gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) equilised = cv2.equilizeHist(image) set_of_images = np.hstack((image, equilised)) cv2.imshow("Images", set_of_images) cv2.waitKey(0)
The image before and after histogram equalization looks :
The major libraries used in this project are -
To install OpenCV(cv2 module) the following command will help:
pip3 install opencv-python
Submitted by Vedant Keshav Jadhav (vedantjad99)
Download packets of source code on Coders Packet