/Histogram-of-an-image

BSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Histogram and Histogram Equalization of an image

Aim

To obtain a histogram for finding the frequency of pixels in an Image with pixel values ranging from 0 to 255. Also write the code using OpenCV to perform histogram equalization.

Software Required:

Anaconda - Python 3.7

Algorithm:

Step1:

Import the necessary libraries and read two images, Color image and Gray Scale image.

Step2:

Calculate the Histogram of Gray scale image and each channel of the color image.

Step3:

Display the histograms with their respective images.

Step4:

Equalize the grayscale image.

Step5:

Display the grayscale image.

Program:

Developed By: Kadin Samson

Register Number: 212221230044

import cv2
import matplotlib.pyplot as plt

Write your code to find the histogram of gray scale image and color image channels.

Gray Image

hist = cv2.calcHist([gray_image],[0],None,[256],[0,255])

Color Image

Chanel Blue

h1 = cv2.calcHist([color_image],[0],None,[256],[0,255]) 

Chanel Green

h2 = cv2.calcHist([color_image],[1],None,[256],[0,255]) 

Chanel Red

h3 = cv2.calcHist([color_image],[2],None,[256],[0,255]) 

Display the histogram of gray scale image and any one channel histogram from color image

Gray Image

import cv2
import matplotlib.pyplot as plt
gray_image =cv2.imread('C640.png',0)
cv2.imshow('gray_image',gray_image) 
cv2.waitKey(0) 
cv2.destroyAllWindows()

Color Image

import cv2
import matplotlib.pyplot as plt
color_image =cv2.imread('C640.png',-1)
cv2.imshow('color_image',color_image) 
cv2.waitKey(0) 
cv2.destroyAllWindows()

Write the code to perform histogram equalization of the image.

equ_img = cv2.equalizeHist(gray_image)

Output:

Input Grayscale Image and Color Image



Histogram of Grayscale Image and any channel of Color Image

Grey Image


Blue Channel


Green Channel


Red Channel


Histogram Equalization of Grayscale Image


Result:

Thus the histogram for finding the frequency of pixels in an image with pixel values ranging from 0 to 255 is obtained. Also,histogram equalization is done for the gray scale image using OpenCV.