An image histogram represents a graphical distribution of pixel intensities in an image. Pixel range can be 0 to 255 that provides 256 possible intensity level for each color channel. Histogram provides an information about the overall contrast, brightness, and intensity and tonal distribution of an image.
By analyzing the distribution of pixel intensities, we can adjust image contrast, brightness, or apply techniques like histogram equalization to improve the overall quality of the image.
OpenCV API provides functions to calculate image histogram and apply equalization techniques. In this tutorial, you'll briefly learn how to build image histogram and apply equalization method by using OpenCV in Python. The tutorial covers:
- Grayscale histogram
- Color histogram
- Histogram equalization
- Source code listing
We'll start by loading the required libraries.
import cv2 from matplotlib import pyplot as plt