0% found this document useful (0 votes)
22 views2 pages

Aashutosh Exp6

The document describes performing histogram equalization on an image using OpenCV in Python. It loads an image, converts it to YUV color space, equalizes the histogram of the Y channel, converts it back to BGR and displays the original and equalized images.

Uploaded by

savitaannu07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Aashutosh Exp6

The document describes performing histogram equalization on an image using OpenCV in Python. It loads an image, converts it to YUV color space, equalizes the histogram of the Y channel, converts it back to BGR and displays the original and equalized images.

Uploaded by

savitaannu07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment 6

Name : Aashutosh Savita


Enrolment No. : 0901AM211001
Branch : AIML VI
Batch : A

Write python code to perform Histogram Equalization


In [ ]: import cv2
import numpy as np
from PIL import Image

IMAGE_SHAPE = (500,450)

In [ ]: img = Image.open("image6.jpg").resize(IMAGE_SHAPE)
img

Out[ ]:

Histogram Equalization: Histogram Equalization is an image processing technique that adjusts the
contrast of an image by using its histogram. To enhance the image's contrast, it spreads out the most
frequent pixel intensity values or stretches out the intensity range of the image

In [ ]: # Check if the image is loaded successfully


if img is None:
print("Error: Could not open or read the image")
else:
# Convert the color image to YUV color space
img_yuv = cv2.cvtColor(np.array(img), cv2.COLOR_BGR2YUV)

# Equalize the histogram of the Y channel


img_yuv[:,:,0] = cv2.equalizeHist(img_yuv[:,:,0])
# Convert the YUV image back to BGR color space
img_output = cv2.cvtColor(img_yuv, cv2.COLOR_YUV2BGR)

# Display the original and equalized images


display('Original Image',img)
display('Equalized Image',Image.fromarray(img_output))
'Original Image'

'Equalized Image'

You might also like