Anda di halaman 1dari 3

Homework 2

ECE 253
Digital Image Processing
October 16, 2015

Instructions :
Homework 2 is due by 11:59 PM, October 24, 2015.
Submit your homework electronically by email to arangesh@ucsd.edu with the subject line
ECE 253 HW2.
The email should have one PDF file of your writeup attached. Make sure it includes your full
name, PID, and email. This file must be named ECE 253 hw2 lastname studentid.pdf.
All problems are to be solved using MATLAB unless mentioned otherwise.
You should avoid using loops in your MATLAB code unless you are explicitly permitted to
do so.
Append source code, floats, matrices, and image outputs, to your writeup where applicable.
Simply pasting your code in the report should suffice, but make sure it is indented correctly.
Problem 1. Histogram Equalization (5 points)
It is often found in image processing and related fields that real world data is unsuitable for
direct use. This warrants the inclusion of a pre-processing step before any other operations are
performed. One example of this is histogram equalization.
The goal of this problem is to write a function in MATLAB with the following specifications:
(i) The function takes one input: the image file name.
(ii) Plots the histogram of each channel of the original image.
(iii) Performs histogram equalization.
(iv) Plots the histogram of each channel of the enhanced image.
(v) The function returns one output: the enhanced image.
Evaluate your function on the image fog.jpg. Feel free to make use of inbuilt MATLAB functions.
In your report, include the original image, the image after equalization, and the 6 histogram plots
mentioned above. Make sure all you plots and images are labeled correctly. Additionally, include
your answers (no more than two sentences each) to the following questions:

What do the original histograms look like (statistically speaking)? If youre lost, do some
research on the derivation of histograms.
What effect does histogram equalization have on the original image (in a visual sense)?

Problem 2. Sampling & Quantization (5 points)


In this problem, we intend to study the effects of sampling and quantization on digital images.
Your job is to write a function with the following specifications:
(i) The function takes one input: the image file name.
(ii) The input image is assumed to be greyscale.
(iii) Sample the image in spatial domain with a sampling rate of 10.
(iv) Do a 5-level uniform quantization of the sampled image so that the bins cover the whole range
of greyscale values (0 to 255). You should not use any MATLAB functions for this.
(v) You are allowed to use loops.
(vi) The function returns one output: the sampled and quantized image.
Evaluate your function on the image peppers.png. In your report, include the original image,
the image after sampling, and the image after both sampling and quantization. In addition to this,
include your answer (no more than two sentences) to the following question:
How would the above function be of use in image compression?

Problem 3. Lloyd-Max Quantizer (10 points)


For this part of the homework, we study the Lloyd-Max quantizer. Before you get started, carefully
study pages 602-603 of the book. Then, proceed to implement the following:
(i) Write a function that takes as inputs a greyscale 8-bit (uint8) image, a scalar s [1, 7] and
performs uniform quantization over the entire range [0, 255] so that the output is quantized
to an s-bit image.
(ii) The m-file lloyds.m is found in the communications toolbox in MATLAB. It performs Lloyd
Max quantization (optimal quantization in the squared error sense). If you dont have this
toolbox (its not standard with the student version), lloyds.m is provided in the data folder.
You can use this function 2 ways:
[partition, codebook] = lloyds(training_set, initcodebook)
where you give it an initial codebook, or
[partition, codebook] = lloyds(training_set, len)
2

where len is the size of the codebook desired.


The input training set is a vector of training data (which is used as an empirical measure of
the probability mass function), so you will have to reshape your image by
[M,N] = size(image);
training_set = reshape(image,N*M,1);
For the images lena512.tif and diver.tif, calculate the MSE values for s [1,7] using both
your uniform quantizer and the Lloyd-Max quantizer. Plot the results (MSE versus number
of bits). Show one plot for lena512.tif (with both uniform and Lloyd-Max quantization) and
another plot for diver.tif. Compare the results for the different quantizers/images and explain
them. That is, why does one quantizer outperform the other, and why is the performance
gap larger for one image than for the other?
(iii) Now use global histogram equalization on lena512.tif and on diver.tif to generate two new
images, for example:
a = histeq(lena512,256);
Repeat part (ii) for these two new images. Compare them with the previous set of plots.
What has happened to the gap in MSE between the two quantization approaches and why?
(iv) Why is the MSE of the 7-bit Lloyd-Max quantizer zero or near zero for the equalized images? One might have thought that equalization is not to the advantage of the Lloyd-Max
quantizer, because equalizing the histogram should be flattening the distribution, making
it more uniform, which should be to the advantage of the uniform quantizer. Explain this
phenomenon.

Anda mungkin juga menyukai