ECE 253 Homework 1 to 6 solutions

$120.00

Original Work ?

Download Details:

  • Name: HWs-302hyv.zip
  • Type: zip
  • Size: 65.24 MB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (1 vote)

ECE 253 Homework 1

1) Cleaning by cluster removal

A photo of a partial textbook page has been thresholded to be a binary image, called badIm, which
looks like this:
We want to extract the chapter number and chapter title and the large black lines, but get rid of
everything else.

So the clean image we are aiming for, called idealIm, looks like this:
We can use xor to find all the pixels where idealIm and badIm are not the same. If we sum up
over the rows and columns of the xor output, we get a count of how many pixels are not the same:
count = sum(sum(xor(idealIm,badIm)))
and we find there are 127,994 pixels different.

We will try to make this count as small as possible.
In Matlab, the function bwareaopen removes small objects (objects with fewer than P pixels)
from an image. Because there are a lot of clusters of black pixels (zero-valued pixels) that need to
be removed, and because bwareaopen considers objects to be one-valued pixels, we will need to
invert the image to operate on it, and then invert again to return the image to its normal appearance.

So, for example, to remove clusters of black pixels with less than 10 pixels, we could use:
clean10 = 1 – bwareaopen(1-badIm,10);
We can then use xor to find and count all the pixels where clean10 is different from idealIm.
We will call these bad pixels.

a) Make a plot where the x-axis (going from 1 to 2500) represents the number of pixels P for
which black objects with fewer than P pixels get removed, and the y-axis is the corresponding
number of bad pixels (that is, the number of pixels where the resulting bwareaopen result
(with parameter P) differs from idealIm). Include the plot in your write-up and the matlab
code which you used to generate it.

b) Explain why the plot has the shape that it does. In particular, there is an initial portion where
the bad pixel count decreases monotonically. What is happening there? Then the curve bottoms
out and goes generally up, but is not monotonic– it has some little ups and downs within a
general upward trend. Why do those occur?

c) What is the minimum value of your curve, and what is the value of x at which that minimum
occurs?

2) Erosion and Dilation

Now we will see how dilation and erosion can do a much better job of this task than the simple
cluster removal.
a) Use imdilate and imerode commands on badIm, using the structuring element ones(3).
How does this do in terms of the count of bad pixels? Try ones(5) and ones(7). Show your
Matlab code and give your numeric results (count of bad pixels) and explain what is going on
in your results.

b) If e5 and e7 denote the output from the previous part with structuring elements ones(5) and
ones(7), it appears visually that e7, compared to e5, gets rid of more noise, but also gets rid
of more of the letters that we want to keep. So we can potentially deploy e7 and e5 with
an approach like “geodesic dilation” and “morphological reconstruction” from Section 9.6, to
try to get back the portions of letters that were eaten away, without getting back the noise.

Make a plot of the number of bad pixel versus the iteration number in this approach, using
the structuring element ones(3). Show your code, and discuss the result.

c) Your choice: Try something else using dilation and erosion, potentially in combination with
other operations or different structuring elements, that gets you even closer to idealIm.
Whatever you try, you have to apply it to the whole image– you can’t just selectively apply
your operator to a section of the image where there is noise.

3) Skeletonization

a) Starting with the image idealIm, use the bwmorph function with ’skel’ to fully skeletonize the image. (You’ll need to invert the image first, or you’ll get weird results.) Explain
the appearance of your results

b) Propose a sequence of steps (you do not have to carry them out) to get rid of the spurs. Your
proposed method should be able to handle the fact that the skeleton components (and their
spurs) are of very different sizes.

4) Pencil and paper problem: Erosion and Dilation

Image B below was produced from A by an operator that used two structuring elements: S1, which
exactly matches one of the small square boxes, and S2 which fits snugly around the small square
boxes.

For example, if the boxes are 3×3 pixels, then S1 would be the 3×3 structuring element
ones(3), and S2 would be a 5×5 ring, where the outer ring pixels have value 1 and the inner 3×3
pixels have value 0. For both S1 and S2, the origin of the structuring element is at the center. The
gray object in B is shown only for reference, and is actually not present.

Determine which of the operations listed below was used in this transformation. Give a brief
explanation.
a) B = [(A ⊖ S1) ∩ (Ac ⊖ S2)] ⊖ S1
b) B = [(A ⊖ S1) ∩ (Ac ⊖ S2)] ⊕ S1
c) B = [(A ⊕ S1) ∩ (Ac ⊖ S2)] ∩ A
d) B = [(A ⊖ S1) ∩ (Ac ⊖ S2)] ∩ A

5) Pencil and paper problem: Skeletons

Match the sets in R2
in the left column with their “skeleton by maximal balls” in the right column.

In other words, for each numbered shape on the left, find the letter of the skeleton it corresponds
to on the right. If you find that an item on the left has no match on the right, then draw what the
skeleton would look like. No explanations are required.

Note #1: The shapes and their skeletons are not necessarily drawn to the same scale, so don’t rule
things out on scale grounds. For example, the line segment in the right column is longer than the
diameter of the disk in the left column; that alone would be enough to rule out a match if these
items were drawn to scale. But you should ignore the scale.

Note #2: Consider these sets are in R2
, and not on a pixel grid in Z
2

ECE 253 Homework 2

1) Histogram Equalization

Use imread to read in the image lungs.jpeg.
This is a grayscale image but is stored as an RGB image with 3 color planes, so you can use:
a = lungs(:,:,1);
imshow(a)
ghe = histeq(a);
imshow(ghe)
to define a grayscale image ”a” and compute the global histogram equalized version (ghe) of it.

a) Read what the function ”cumsum” does. Carry out the following sequence of steps:
[n,y] = imhist(a,256);
map = cumsum(n);
map = map / max(map);
plot(y,map)
imshow(a, [map map map])
Explain what ”map” represents, what the plot shows, and what image is being shown with this
imshow command.

b) The dark background on this image is hurting the histogram equalization of this image.
Manipulate the histogram in some way which will help this problem, and explain what you
did. Then use cumsum to generate a new map, and show your image with this new map.
Plot the new map on the same plot as the previous one, and interpret the differences in your
equalized images relative to the differences in these plots. Include your plot with 2 curves and
your explanation of results.

2) Noise Cleaning

Load the files cleanbaby.mat (the baby image without added noise), babyS.mat (the baby image
with salt noise added, in the form of little vertical streaks), and baby2.mat (the baby image with
both salt noise and a low level of Gaussian noise).

a) Use medfilt2 with a 1×3 median filter to clean up the babyS image, and also to clean up the
baby2 image. Likewise use a 3×3 median filter to clean them up. In all four cases, use the
function immse to compute the mean squared error (MSE) between your filtered output and
the cleanbaby image. You should find that the 3×3 filter does better (in terms of MSE) than
the 1×3 filter for one of the noisy images but the 1×3 is better for the other. Explain why this
occurs, and provide your matlab commands and your MSE values.

b) Try the sequential use of a median filter and a spatial averaging filter on the baby2 image that
has both noise types. Provide your Matlab code, the MSE between your output image and the
cleanbaby image, and a discussion of your results.

3) Unsharp Masking

a) You are to spatially enhance an image using unsharp masking. Consider the following MATLAB function:
function im_out = unsharp( im_in, maskA, weight )
[a,b] = size( maskA );
maskB = zeros( size( maskA)); maskB(ceil(a/2),ceil(b/2)) = 1;
maskC = maskB – maskA;
maskD = maskB + weight * maskC;
im_out = conv2(im_in,maskD,’valid’);

Here im in is the input image and im out is the output image. Suppose maskA is a small
odd-sized lowpass filter mask, and weight is a positive number. What kind of masks are masks
B, C and D? Using the discussion from class on separating an image into lowpass and highpass
components, explain how this function performs edge sharpening.

b) In unsharp masking you can choose which lowpass filter to use and how much weight to give
the highpass part. We will investigate the effect of these on the resulting image. First, create
a test image of size 128 × 128 that consists of a ramp and simple step function, as follows:
tst=ones(128,1)*[64*ones(1,32) (64:4:188) 192*ones(1,32) 64*ones(1,32)];

This has four equal sized areas (from left to right): first, 32 columns with value 64, then
32 columns of ramp going from 64 to 192, then 32 columns with value 192 and finally 32
columns with value 64. Try a few combinations of low pass filters and weights. Vary the
size of the mask (e.g., 3 × 3, 5 × 5, maybe even 7 × 7) and the entries in the mask (e.g.,
unweighted averaging vs. strongly center-weighted averaging) and vary the extra weight given
to the highpass part.

Discuss the results in each case, and note any trends you see that arise
from varying the parameters. Also look at a slice of the filtered images:
plot(tst(64,:));
Include in your homework a few of the plots of horizontal slices through the filtered images,
with discussions of the trends.

c) For a real-world example at larger size, read in the image ”blurry-moon.tif” and use highboost
filtering on it starting with the following Gaussian lowpass filter:
f = 1/159








2 4 5 4 2
4 9 12 9 4
5 12 15 12 5
4 9 12 9 4
2 4 5 4 2








Try different boost values. Provide your code and your output image, and comment on your
result.

4) Order of Operations (this is not a Matlab problem)

An image has been corrupted with a low level of additive Gaussian noise, and with 1% of salt
and pepper noise. The noise is independent from pixel to pixel. We will process the image with
3 operations in some order: contrast manipulation, median filtering, and spatial averaging filtering.
Consider that the image is stored as values ranging from 0 to 1.

• The contrast manipulation (CS) consists of remapping an input value s to an output value r
according to r =

s
• The median filter (MF) is a 3×3 median filter
• The spatial averaging (SA) filter is the unweighted 3×3 mean filter
The 3 operations can be done in 6 possible orders:
A: MF → SA → CS
B: CS → MF → SA
C: SA → CS → MF
D: MF → CS → SA
E: SA → MF → CS
F: CS → SA → MF

a) Which of these systems, if any, will produce an output image that is exactly the same as the
output from another system? Explain why?

b) Which of these systems, if any, do you expect to do better at noise removal? You are not
being asked for a complete ranking of the systems, but rather just to point out (and explain)
if certain placement orders clearly outperform some other ones for this noise removal task.

ECE 253 Homework 3

1) Chromaticity Diagrams

The text file called cie contains color matching functions in the XYZ coordinate system. The format
of the file is wavelength X Y Z from 380 nanometers to 780 nanometers. You can read it in
using:
load cie -ascii

For this problem we ask you to include your plots as well as of your Matlab commands and
interpretations.

(a) On one graph, plot the color matching functions, X(λ), Y (λ), Z(λ). On another graph, plot the
xy chromaticity diagram. Connect the “line of purples” on your diagram.

(b) In lecture 11, the conversion from the CIE RGB space to CIE XYZ space is given by the
following linear transformation:



X
Y
Z


 =



0.49000 0.32000 0.2
0.17697 0.81240 0.01063
0 0.01 0.99000






RC
GC
BC


Inside the xy chromaticity diagram for CIE XYZ space, plot the triangle that corresponds to the
color gamut of the CIE RGB spectral primary system. You should use this 3×3 linear transformation
to transform the coordinates in one system to the other system.

(c) The conversion from the CIE XYZ space to the NTSC receiver primary system RN , GN , BN is
given by the following linear transformation:



RN
GN
BN


 =



1.910 −0.533 −0.288
−0.985 2.000 −0.028
0.058 −0.118 0.896






X
Y
Z


The Society of Motion Picture and Television Engineers (SMPTE) made its own receiver primary
2
color coordinate system. The conversion from the CIE XYZ space to the SMPTE receiver primary
system RS, GS, BS is given by the following linear transformation:



RS
GS
BS


 =



3.508 −1.741 −0.544
−1.069 1.977 0.035
0.056 −0.197 1.051






X
Y
Z


Suppose there existed two sets of phosphors which exactly corresponded to the NTSC and SMPTE
primaries. Inside the xy chromaticity diagram, plot the two triangles that correspond to the color
gamuts of these two sets of phosphors. Does it appear that the NTSC or SMPTE primaries provide
a larger gamut?

(d) On a separate plot of the xy chromaticity diagram, plot the triangle that corresponds to the color
gamut of the CIE RGB spectral primary system, in which the monochromatic spectral primaries
(Red=700nm, Green=546.1nm, Blue=435.8nm) were used for the original color matching experiment. In part (b), we already did this by using a 3×3 linear transformation to go between the CIE
XYZ and CIE RGB color systems. However, in this part you should do this (in an approximate
way) by directly using the data in the cie file.

2) Contrast and saturation enhancement for color images

Read the image PeopleWalking.jpeg into Matlab. It is of size 500 by 1110. If the image is called
”im”, you can break it into RGB color planes as follows:
>> r = im(:,:,1);
>> g = im(:,:,2);
>> b = im(:,:,3);

You can convert the RGB planes to HSI and back again using the routines rgb2hsi.m and hsi2rgb.m
which are based on the formulation from Gonzalez and Woods (except that we keep the angles in
radians, not degrees).
>> [h,s,i] = rgb2hsi(r,g,b);

The rgb2hsi routine expects inputs in the range of 0 to 255; check to be sure that your input ranges
are correct. The h,s,i outputs from it are between 0 and 1. After processing in the HSI domain, you
can convert back using hsi2rgb to obtain new RGB color planes For hsi2rgb.m, the h,s,i inputs must
be between 0 and 1. The r,g,b outputs, however, are not necessarily restricted to the range 0–255.

(a) Use Matlab’s histeq command to equalize the intensity plane ”i”. Convert back to RGB using
hsi2rgb.m. Then if the new color planes are called rHE, gHE, bHE you can put them together into
a color image using:
imHE = reshape([rHE gHE bHE], 500, 1110, 3);

Provide your equalized image. Where do you see shifts in hue arising in the histogram equalized
image? Give an explanation for why they occur in specific regions of the image.

(b) Going back to the HSI color planes before doing equalization, now we will try enhancing the
saturation of this picture. First try creating a new saturation plane as newS = sqrt(s). How does the
image look? Explain what you see. In particular, what happens to the woman’s white hair and white
shirt, and why does this happen?

(c) See if you can obtain more visually pleasing saturation enhancement results. Try one other
transformation function of your choice on the saturation plane. Provide your image, a plot of your
transformation function, and discussion of results.

3) Change of Reference White

We are given tristimulus values T1, T2 and T3 for a color C. The tristimulus values are relative to
a reference white W1. In other words, for our color, the tristimulus values are given by
T1(C) = A1(C)
A1(W)
T2(C) = A2(C)
A2(W)
T3(C) = A3(C)
A3(W)

You may interpret the A’s as power knob settings in the color matching experiment. What would the
new tristimulus values Tˆ
1, Tˆ
2, and Tˆ
3 be for our color C in a coordinate system that uses the same
primaries but uses a reference white W2?

Derive your expression in terms of the tristimulus values
in the original coordinate system. So your expression for the Tˆ’s should involve only T’s and no A’s.

4) Adding Colors

In some color system, color C has tristimulus values T1, T2 and T3. Its chromaticity coordinates are
t1 = 0.1 and t2 = 0.1. Let W denote the reference white for the color system. We form an additive
mixture of colors: A =
1
2
(C + W). (Note: The color A is in this problem has nothing to do with
the A’s in the previous problem. Here, A represents a color.)

a) What are the tristimulus values (call them R, G, and B) for color A? What are the chromaticity
coordinates for A? (Call them r and g.)

b) Within the chromaticity diagram, consider the line segment that goes from the chromaticity
coordinates for C to the chromaticity coordinates for W. Show that color A is represented on
the chromaticity diagram by a point on that line segment.

ECE 253 Homework 4

1) 2D Sampling and Aliasing

For this problem, it might be useful to remember the following Fourier transform pair:
cos(2π(u0x + v0y)) ↔
1
2
(δ(u − u0, v − v0) + δ(u + u0, v + v0))

a) Try the following in Matlab:
[x y] = meshgrid(0:256,0:256);
z1 = cos( 2 * pi * 1/32 .* x – 2 * pi * 1/128 .* y);
z2 = cos( 2 * pi * 1/4 .* x – 2 * pi * 7/8 .* y);
z3 = cos( 2 * pi * 1/2 .* x – 2 * pi * 1/2 .* y);

Look at the images (matrices) x, y, z1, z2, z3 (and you might want to inspect their numeric values
too). The meshgrid function has the effect of sampling the three underlying continuous functions
with sampling period T=1 in both the x and y directions. Discuss the appearances of the three
sampled images, z1, z2, and z3. Are the underlying continuous functions getting undersampled?
critically sampled (sampled at Nyquist)? oversampled? Explain what you see in terms of the spatial
frequencies and the sampling frequency.

b) What values would we have to choose for ”a” and ”b” in the expression:
z4 = cos( 2 * pi * a .* x – 2 * pi * b .* y);
so that the sampled function would be aliased and would have an appearance identical to that of
the sampled and displayed function z1?

2) Pre-filtering to Reduce Aliasing before Sampling

Aliasing can be analyzed by finding the foldover frequency, and looking at the area under the
folded-over curve. Prefiltering reduces the aliasing power, but it also reduces the signal power in
the part of the spectrum we would like to keep intact. This problem will examine this reduction in
signal power and noise power that comes from pre-filtering.

Read in the images barbara.tif and baby.tif. We will use a 512×512 section of each, as follows:
>> barbBig = barbara(1:512,37:548);
>> babyBig = baby(201:712,201:712);

The power spectrum is given by the square of the magnitude of the Fourier Transform. So, the
power spectrum for the cropped baby image, prior to downsampling, is given by:
babyfft_1 = fftshift(abs(fft2(babyBig)).∧2);
and the total image energy can be found by summing all the values in that array. We can visualize
the power spectrum by using
>> babyspectrum = log(babyfft_1 + 1);
>> imshow(babyspectrum / max(max(babyspectrum)))

a) In the power spectrum babyfft 1, where is the DC coefficient located? How can you check that?
You will need to understand where the function fft2 puts the DC coefficient, and then where fftshift
relocates it to.

b) Compare visually the images babyBig and barbBig, and their power spectra. Based on the visual
comparison, which of the two images has more high frequency content? Which one do you expect
to have more of an aliasing problem from downsampling?

c) We will use the following commands to generate two downsampled versions of babyBig and
similarly generate two downsampled versions of barbBig. Be sure you understand what imresize
with the 0.125 and ’nearest’ parameters is doing:
baby64_1 = imresize(babyBig,0.125,’nearest’);
babylow = filter2(ones(8)/64,babyBig);
baby64_2 = imresize(babylow,0.125,’nearest’);

Compare visually the two 64× 64 versions of baby, and of barbara. Comment on the differences
and explain them. In particular, address whether the pre-filtering helps more for baby or for barbara.

d) Assume that (for each image) the underlying continuous image field was sampled at the Nyquist
rate to form the original (cropped) 512× 512 discrete image. So the original sampling distance is
1, and the original sampling frequency is 1, which is the critical sampling frequency.

Since we are downsampling by a factor of 8, that corresponds to a new sampling distance of 8,
and a sampling frequency of 1/8. So what portion of the spectrum is aliased and what portion is
not? The tricky thing here is figuring out things in Matlab’s pixel units and Matlab’s coordinate
system.

Matlab actually indexes the array from 1 to 512 on both axes. But after doing the fftshift,
it is useful to think of this as going from -256 to +256, where the highest frequency in u (or v)
occurs at the first/last row/column.

For the barbBig image, for the subsampling from 512 x 512 down to size 64 x 64, estimate the
reduction in aliasing power and the reduction in signal power that come from the prefiltering.

3) Non-rectangular sampling

An image has its spectrum confined to the region shown below.
(a) Find a generator matrix for the rectangular sampling lattice that has the lowest sampling density
which can still ensure no aliasing (no overlap of spectral replications).

(b) Find a generator matrix for the non-rectangular sampling lattice that has lowest sampling density
that could prevent the spectral replications from overlapping.

(c) What percentage reduction in samples can we get by sampling on the non-rectangular grid as
opposed to the rectangular grid?

ECE 253 Homework 5

1) Scalar Quantization

Suppose that a random variable X has the two-sided exponential pdf
fX(x) = λ
2
e
−λ|x|

A three level quantizer q for X has the form
q(x) =



+b for x > a
0 for −a ≤ x ≤ +a
−b for x < −a

(a) Find a simple expression for b as a function of a so that the centroid condition is met. You may
use that:
Z ∞
c
xe−λxdx =
ce−λc
λ
+
e
−λc
λ

(b) For what value of a will the quantizer satisfy the nearest neighbor condition for optimality (using
b chosen as above, so the centroid condition is satisfied too)? Give specific values for a and b in
terms of λ.

2) Lloyd Algorithm for Quantizer Design

A 3-level quantizer is to be designed to minimize mean squared error using the Lloyd algorithm
with the training set
T = {1, 2, 3, 4, 8, 9, 12}

If we start with the initial codebook C0 = {2.0, 6.0, 10.0} what does it converge to? You will
find you need to enunciate a tie-breaking rule, that is, if a training point is exactly on a decision
boundary, then does it belong to the partition region on the left, or to the one on the right? Try it
both ways.

Show the sets of transition (decision) levels and the sets of quantization (reproduction)
level for all steps of the Lloyd Algorithm. Final answer within one decimal place of precision is
adequate. A computer is not needed.

3) Comparing quantization for images

a) Write a function that takes as inputs an 8-bit image and a scalar s ∈ [1, 7] and performs
uniform quantization so that the output is quantized to a s-bit image.

b) The m-file lloyds.m is found in the communications toolbox in MATLAB. It performs Lloyd
Max quantization, attempting to minimize mean square error through an iterative algorithm
(just as you did in the previous problem) by alternating between optimizing the quantization
levels for the given partition (decision levels) and optimizing the partition for the current
quantization levels. If you don’t have this toolbox lloyds.m (and quantiz.m which is called by
lloyds) are provided on Piazza.

You can use lloyds in various ways:
[partition,codebook] = lloyds(training set,initcodebook)
where you give it an initial codebook, or
[partition, codebook] = lloyds(training set, len)
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 an image into a vector to use it as the training data for lloyds:
>> [N,M] = size(image);
>> training_set = reshape(image,N*M,1);

You are given three images: vase.tif, testpattern512.tif, and astronaut.tif. For each image,
calculate the mse values for s = 1, . . . , 7 using both your uniform quantizer and lloyds.m.

Plot the results. Show one plot for vase (with both uniform and Lloyd Max quantization),
a second plot for testpattern512, and a third plot for astronaut. Compare the results for the
different quantizers/images and explain them. (It will help to examine the histograms of the
three images to understand the performance of the quantizers.)

In particular, you should answer
the following questions:
• Which quantizer does better in general, and why?
• At the low end (1 or 2 bits for the quantization), if you look at the ratio of the performance
between the two types of quantization, for which image is that ratio largest, and for which
image is it smallest, and why?

c) Here we consider whether quantizers can get worse distortion with increasing bit rate.
• In the plots, the MSE for the Lloyd quantizer decreases as expected with increasing bit rate.

But for the uniform quantizer, for one of the images, the quantizer gets worse at one point
when it is given an increase in bits. Why does this happen?

• Although for these images we don’t see the Lloyd quantizer getting worse with increasing
bit rate, is it possible that this could happen with the Lloyd algorithm?

ECE 253 Homework 6

1) Truncated Huffman Coding

Consider the alphabet with 14 possible symbols and their associated probabilities given on slide 22
of Pre-Lecture19.

(a) Construct a full Huffman code for this source. Show your source reduction steps, and give the
final codewords for each symbol.

(b) What is the entropy of this source?

(c) What is the expected length and the efficiency of your full Huffman code? How do they compare
to the expected length and the efficiency of the truncated Huffman code for this source given on
slide 23?

2) Arithmetic Coding

Consider a four-symbol source {a, b, c, d} with source probabilities {0.1, 0.4, 0.3, 0.2}. Arithmetically encode the sequence bba. Use the division of the unit interval where symbol a corresponds to
the sub-interval [0, 0.1), symbol b corresponds to the sub-interval [0.1, 0.5), etc. Use the interval
rescaling approach. For each input symbol, show the corresponding interval(s) and the bits put out,
if any.

3) DCT and DFT

Let f(k) denote a one-dimensional N-point sequence that is zero outside 0 ≤ k ≤ N − 1. The
unitary N-point DCT is given by
C(u) = α(u)
N
X−1
k=0
f(k) cos 
(2k + 1)uπ
2N

where
α(u) = ( p
1/N if u = 0
p
2/N if u = 1, 2, . . . , N − 1
Let g(k) be the reflected sequence:
g(k) = (
f(k) for k = 0, 1, . . . , N − 1
f(2N − 1 − k) for k = N, N + 1, . . . , 2N

The 2N-point unitary DFT of g(k) is:
G(u) = 1

2N
2
X
N−1
k=0
g(k)e
−j2πuk/2N

Derive the relationship stated in class between the 1D N-point DCT of f(k) and the 1D 2N-point
DFT of g(k).

4) JPEG

a) Read in the image totem-poles.tif. How many bits per pixel is this initial representation of the
image? To answer this, simply find the number of pixels in the image, find the number of
bytes that the file takes up on your computer’s storage, and calculate bits per pixel (bpp).

b) Generate a curve of of PSNR versus rate (bits per pixel) for compressing this image with
baseline sequential JPEG. You can do this by using imwrite to write out the image as a JPEG
file with different quality factors.

Each time you write it out, you can check the size of the
output file, and read the image back in to find the PSNR, for example:
>> imwrite(totem,’totem50.jpg’,’Quality’,50)
>> totem50 = imread(’totem50.jpg’);
>> impsnr50 = psnr(totem,totem50,255)
impsnr50 =
34.7750

Try quality factors of 1 (worst quality), 70 (very high quality), and at least 4 points in between.
Create a table that has columns for quality factor, bits per pixel, and PSNR. Also plot your
results as PSNR versus bpp.

Look at the images and the PSNR curve and discuss the results
in terms of what artifacts dominate at low bit rates, at what rate is the image visually the same
as the original, and the general shape of the curve (e.g., does PSNR increase linearly with bit
rate?).

c) Let’s see how downsampling can play into low rate coding. Use imresize to downsample the
totem image by a factor of F in each direction, where you are asked to try both F=2 and F=4.

Compress each small version at different quality factors as in the previous part. When you read
the image back in, use imresize to upsample the image back to the original size, and compute
the PSNR relative to the original full size totem image.

Plot the original PSNR vs. bpp curve
and the ones for F=2 and F=4 on the same plot (so bpp is always referring to the bits per pixel
at the original full size).

Choose your set of quality factors such that you cover both the very
low rates which are below what can be achieved by full-size JPEG encoding, and you also
overlap somewhat the set of rates achieved by full-size coding, so you can compare directly
with it. Discuss your results.

d) Lastly, consider the image ”totem1” which comes from compressing the original full size totem
image using a quality factor of 1. If you are trying to be an extra smart JPEG decoder, what
can you do to improve this received image? Try at least one improvement and report your
PSNR relative to the original totem image.