Histograms Equalization using Python OpenCv Module

PythonProgrammingServer Side Programming

Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

Practical Data Science using Python

22 Lectures 6 hours

This is a method in image processing to do contrast adjustment using the image's histogram.

Actually this method usually increases the global contrast of many images, especially when the usable data of the image is represented by close contrast values and through this adjustment, the intensities can be better distributed on the histogram and it allows for areas of lower local contrast to gain a higher contrast.

OpenCV has a function to do this, cv2.equalizeHist() and its input is just grayscale image and output is our histogram equalized image.

This technique is good when histogram of the image is confined to a particular region and it won't work good in places where there are large intensity variations and where histogram covers a large region, i.e. both bright and dark pixels are present.

Example Code

import cv2
# import Numpy
import numpy as np
equ = cv2.equalizeHist(my_img)
# stacking both the images side-by-side orientation
res = np.hstack((my_img, equ))
# showing image input vs output
cv2.imshow('image', res)
cv2.waitKey(0)
cv2.destroyAllWindows()


Output

Updated on 30-Jul-2019 22:30:23