0% found this document useful (0 votes)
48 views7 pages

CV Lab 3 Muhammad Umer Siddiq

This lab report discusses applying histogram equalization to an image. The student first performs histogram equalization manually by calculating the original histogram, normalizing it to a PDF, calculating the CDF, using the CDF to derive an equalization function, and applying the function to equalize the image. They then apply histogram equalization using the cv2 function and compare the results. In the conclusion, they summarize that histogram equalization improves contrast by mapping pixel intensities to a more uniform distribution derived from the image's CDF.

Uploaded by

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

CV Lab 3 Muhammad Umer Siddiq

This lab report discusses applying histogram equalization to an image. The student first performs histogram equalization manually by calculating the original histogram, normalizing it to a PDF, calculating the CDF, using the CDF to derive an equalization function, and applying the function to equalize the image. They then apply histogram equalization using the cv2 function and compare the results. In the conclusion, they summarize that histogram equalization improves contrast by mapping pixel intensities to a more uniform distribution derived from the image's CDF.

Uploaded by

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

Computer Vision

Lab Report # 3

Name: Muhammed Umer Siddiq


Reg no: 296908
Degree: DE 41 EE B

Task: Apply Histogram Equalization, first on your own, then using the cv2
function.

Code:
import sys

if "google.colab" in sys.modules:
    import subprocess

    subprocess.call("apt-get install subversion".split())
    subprocess.call(
        "svn export https://github.com/YoniChechik/AI_is_Math/trunk/
c_02a_basic_image_processing/Unequalized_Hawkes_Bay_NZ.jpg".split()
    )

import numpy as np
import matplotlib.pyplot as plt
import cv2

figsize = (7, 7)
# read as grayscale
I = cv2.imread("/content/drive/MyDrive/Colab Notebooks/abc.jpg", 0)

plt.figure(figsize=figsize)
plt.imshow(I, cmap="gray", vmin=0, vmax=255)
plt.title("Original image")
plt.show()
# calculating and showing the original histogram

bins_edges_min_max = [0, 256]
num_bins = 256
bin_count, bins_edges = np.histogram(I, num_bins, bins_edges_min_max)
bins_start = bins_edges[:-1]
def draw_hist(x_axis, input):
    fig, ax = plt.subplots(figsize=figsize)
    plt.bar(x_axis, input, width=input.shape[0] / (x_axis[-1] - x_axis[0] 
+ 1))
    return fig, ax

draw_hist(bins_start, bin_count)
plt.title("Original histogram")
plt.show()
# Normalizing the histogram to get PDF

pdf = bin_count / np.sum(bin_count)

draw_hist(bins_start, pdf)
plt.title("Original PDF")
plt.show()
# Calculating CDF

cdf = np.cumsum(pdf)

plt.figure(figsize=figsize)
plt.plot(cdf)
plt.title("Original CDF")
plt.show()
# PDF and CDF ploted on a single plot

fig, ax = draw_hist(bins_start, pdf)
ax.plot(cdf * np.max(pdf), "r")
plt.title("Original PDF+ const*CDF to show the connection between the two"
)
plt.show()
# unnormalizing CDF to get equalization function

f_eq = np.round(cdf * 255).astype(int)

f_eq
# Using the equaization function to get the equalized image

I_eq = f_eq[I]

plt.figure(figsize=figsize)
plt.imshow(I_eq, cmap="gray", vmin=0, vmax=255)
plt.title("equalized image")
plt.show()

Output:
Conclusion:
Histogram Equalization is a technique used when the contrast of the image is too
high or too low. It works by mapping the pixel intensities in the image to a new
distribution that is more uniform. This is achieved by computing the CDF of the
pixel intensities in the image and then mapping the original pixel intensities to new
values using a transformation function that is derived by normalizing the CDF and
multiplying it by the maximum pixel value of an image.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy