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 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# import Opencv
import cv2
  
# import Numpy
import numpy as np
  
# read a image using imread
img = cv2.imread(\'F:\\do_nawab.png\', 0)
  
# creating a Histograms Equalization
# of a image using cv2.equalizeHist()
equ = cv2.equalizeHist(img)
  
# stacking images side-by-side
res = np.hstack((img, equ))
  
# show image input vs output
cv2.imshow(\'image\', res)
  
cv2.waitKey(0)
cv2.destroyAllWindows()

chevron_right



Output :

  


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.