Image Enhancement with Histogram Equalization

  • Share this:

Code introduction


This function reads an image file, converts it to a grayscale image, and then applies histogram equalization to enhance the contrast of the image.


Technology Stack : OpenCV, NumPy

Code Type : Image processing

Code Difficulty : Intermediate


                
                    
import cv2
import numpy as np

def random_histogram_equalization(image_path):
    # Load the image
    image = cv2.imread(image_path)
    
    # Convert the image to grayscale
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    
    # Apply histogram equalization to the grayscale image
    equalized_image = cv2.equalizeHist(gray_image)
    
    return equalized_image                
              
Tags: