Histograms Equalization in OpenCV
Prerequisite : Analyze-image-using-histogram
Histogram equalization is a method in image processing of contrast adjustment using the image’s histogram.
This method usually increases the global contrast of many images, especially when the usable data of the image is represented by close contrast values. Through this adjustment, the intensities can be better distributed on the histogram. This allows for areas of lower local contrast to gain a higher contrast. Histogram equalization accomplishes this by effectively spreading out the most frequent intensity values. The method is useful in images with backgrounds and foregrounds that are both bright or both dark.
OpenCV has a function to do this, cv2.equalizeHist(). Its input is just grayscale image and output is our histogram equalized image.
Input Image :
Below is Python3 code implementing Histogram Equalization :
import cv2
import numpy as np
img = cv2.imread(\ 'F:\\do_nawab.png\' , 0 )
equ = cv2.equalizeHist(img)
res = np.hstack((img, equ))
cv2.imshow(\ 'image\' , res)
cv2.waitKey( 0 )
cv2.destroyAllWindows()
|
Output :
Last Updated :
04 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...