Docsity

Introduction to Computer Vision - Lab Assignment 3 | CSE 185, Assignments of Computer Science

Toggle sidebar
bg1
Lab Assignment #3
Hardcopy due Wed. 11/12 by midnight
(submit in class, in lab, or under my office door)
Title: Histogram Equalization
In this lab, you will implement a function that performs histogram equalization on a grayscale
image. You can assume all images are grayscale and have values from 0 to 255.
a) Write the function compute_histogram that takes a grayscale image as input and returns a
length 256 vector h which is the normalized histogram of the values in the image. h should
have values from 0 to 1 and its components should sum to 1.
b) Write the function plot_histogram that takes as input a histogram (as returned from
compute_histogram) and plots it similar to the plots shown below. The x-axis should
range from 0 to 255 and be labeled “intensity value”. The y-axis should range from 0 to the
maximum value of the histogram and should be labeled “PMF” (for probability mass function).
c) Write the function histogram_transform which takes as input a histogram (as returned
from compute_histogram) and returns a length 256 vector T which represents the
transformation function for histogram equalization. That is, when you index into T using a
pixel value from an input image (offset by 1), you get the value of the pixel in the output
image. Thus T is a look-up-table for the transformation. T should be computed using equation
3.3-8 in the text.
d) Write the function equalize which takes as input a grayscale image and returns the grayscale
image which is the histogram equalized version of the input. This function should:
• Call compute_histogram to compute the histogram of the input image.
• Call plot_histogram to plot the histogram of the input image. Consider using
the bar function. You can change the range of the axes using the axis function.
You can change the labels of the axes using the xlabel and ylabel functions.
• Call histogram_transform to compute the transformation function T.
• Use the transformation function T to produce a histogram equalized version of the
input image.
• Call compute_histogram to compute the histogram of the equalized image.
pf3
pf4

Partial preview of the text

Download Introduction to Computer Vision - Lab Assignment 3 | CSE 185 and more Assignments Computer Science in PDF only on Docsity!

Lab Assignment

Hardcopy due Wed. 11/12 by midnight

(submit in class, in lab, or under my office door)

Title: Histogram Equalization

In this lab, you will implement a function that performs histogram equalization on a grayscale image. You can assume all images are grayscale and have values from 0 to 255.

a) Write the function compute_histogram that takes a grayscale image as input and returns a length 256 vector h which is the normalized histogram of the values in the image. h should have values from 0 to 1 and its components should sum to 1.

b) Write the function plot_histogram that takes as input a histogram (as returned from compute_histogram) and plots it similar to the plots shown below. The x-axis should range from 0 to 255 and be labeled “intensity value”. The y-axis should range from 0 to the maximum value of the histogram and should be labeled “PMF” (for probability mass function).

c) Write the function histogram_transform which takes as input a histogram (as returned from compute_histogram) and returns a length 256 vector T which represents the transformation function for histogram equalization. That is, when you index into T using a pixel value from an input image (offset by 1), you get the value of the pixel in the output image. Thus T is a look-up-table for the transformation. T should be computed using equation 3.3-8 in the text.

d) Write the function equalize which takes as input a grayscale image and returns the grayscale image which is the histogram equalized version of the input. This function should:

  • Call compute_histogram to compute the histogram of the input image.
  • Call plot_histogram to plot the histogram of the input image. Consider using the bar function. You can change the range of the axes using the axis function. You can change the labels of the axes using the xlabel and ylabel functions.
  • Call histogram_transform to compute the transformation function T.
  • Use the transformation function T to produce a histogram equalized version of the input image.
  • Call compute_histogram to compute the histogram of the equalized image.
  • Call plot_histogram to plot the histogram of the equalized image.
  • The function equalize should also print to the console the mean and standard deviations of the input and equalized images. You can use the built in Matlab functions mean and std to compute these directly from the images but first you will need to transform you image matrices into vectors using the Matlab construct your_image_matrix(:) (and possibly convert your images to type double).

Apply your equalize to the following two images available at the course website (on the schedule page):

  • Fig0222(a)_dark.tif
  • Fig0222(b)_light.tif

For each image, turn in:

  • The plot of the histogram of the original image.
  • The histogram equalized version of the image.
  • The plot of the histogram of the equalized image.
  • The mean and standard deviation of the original and equalized versions.

In your results section, simply discuss if you think the histogram equalized versions are improvements over the light and dark images. Also discuss whether the equalized versions look as good as the original image (that you’ve used before in your lab) and why or why not.

Histogram of equalized image

Original image: mean= 60.65, standard deviation= 46.

Equalized image: mean= 129.04, standard deviation= 72.74 (note that your results may not be exactly the same as mine)