
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Histograms Equalization using Python OpenCv Module
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.
Input

Example Code
import cv2 # import Numpy import numpy as np # reading an image using imreadmethod my_img = cv2.imread('C:/Users/TP/Pictures/west bengal/bishnupur/pp.jpg', 0) 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

- Related Articles
- Histogram equalization on an image in OpenCV using Java.
- How to compare histograms of two images using OpenCV Python?
- Reading an image using Python OpenCv module
- Draw geometric shapes on images using Python OpenCv module
- How to plot histograms of different colors of an image in OpenCV Python?
- How to compute and plot 2D histograms of an image in OpenCV Python?
- How can matplotlib be used to create histograms using Python?
- How can I render 3D histograms in Python using Matplotlib?
- Testing in Python using doctest module
- ASCII art using Python pyfiglet module
- Python Generate QR Code using pyqrcode module?
- Prefix matching in Python using pytrie module
- Plotting profile histograms in Python Matplotlib
- Template matching using OpenCV in Python
- Arithmetic operations using OpenCV in Python
