Apply Histogram Equalization to an Image using OpenCV

Apply Histogram Equalization to an Image using OpenCV

Histogram equalization is a method in image processing that allows to adjust the contrast of an image using histogram. Histogram equalization transforms pixel intensity values so that the histogram of the output image is more distributed through the entire range of values.

OpenCV provides the equalizeHist function that allows to apply histogram equalization to a grayscale image.

Python
C++
C++ (CUDA)
Java
import cv2 img = cv2.imread('test.jpg') grayImg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) equImg = cv2.equalizeHist(grayImg) cv2.imshow('Original image', grayImg) cv2.imshow('Equalized image', equImg) cv2.waitKey(0) cv2.destroyAllWindows()

Result:

Applying histogram equalization using OpenCV

Leave a Comment

Cancel reply

Your email address will not be published.