Professional Documents
Culture Documents
INSTITUTE (VJTI)
Histogram
A histogram represents the distribution of pixel intensities in an image. It plots the frequency of
occurrence of each intensity level on the x-axis against the number of pixels having that
intensity level on the y-axis. Histograms are useful for analyzing the brightness and contrast
characteristics of an image.
Code Explanation
import cv2
from google.colab.patches import cv2_imshow
import numpy as np
Explanation:
● Compute Histogram: The compute_histogram function calculates the histogram of the
input image using NumPy's histogram function.
● Calculate Normalized Cumulative Sum: The normalized_histogram function calculates
the normalized cumulative sum of the histogram values, which represents the mapping
function for histogram equalization.
● Histogram Equalization: The histogram_equalization function applies histogram
equalization to the input image using the mapping function obtained in the previous step.
● Loading Image and Displaying: The code loads the input image using OpenCV
(cv2.imread) and displays it using cv2_imshow.
● Step-wise Execution: The code executes histogram equalization in three steps:
computing the histogram, calculating the normalized cumulative sum, and transforming
the input image.