(10 points) Box filter observations and commentary (D.6,
D.7)
(10 points) Professionalism of write-up
Exercises
A. Gaussian Fourier Transform
The command linspace gives a vector of N linearly spaced
numbers between an upper and lower bound. We can combine this with
meshgrid to generate a domain for creating and plotting functions.
Create a 256×256 domain over -20 to 20 as follows.
create a matrix containing a 2-dimensional Gaussian with a variance
of 1 using the domains for x and y you created above.
Normalize your gaussian kernel matrix so that its contents sum to
1.
Use mesh to plot your kernel in a new figure window.
Use fft2 to take the Fourier transform of your Gaussian kernel.
Use mesh to plot the magnitude of the kernel's Fourier transform
(don't forget that you need to do fftshift on the result
before you visualize it.)
How do the two mesh plots compare?
B. Filtering in the Frequency Domain
Recall that the convolution theorem dictates we can do filtering in
the frequency domain. In this part of the lab you'll "do" convolution
without calling conv2.
Load the cameraman image and convert it to doubles.
X = im2double(imread('cameraman.tif'));
Take the Fourier transform of the cameraman.
Use imshow to display the (shifted
and log compressed) magnitude of the cameraman transform. Save this
image using print.
Use imshow to display the (shifted
and log compressed) magnitude of the Gaussian kernel transform. Save
this image using print.
Take the componentwise product of the cameraman and Gaussian kernel
transforms.
Use imshow to display the (shifted and
log compressed) magnitude of the product. Save this image using print.
What effect does this product have on
the low and high frequencies, respectively?
Take the inverse Fourier transform with ifft2. You'll likely
need to extract the real component of the result (using the command
real), and you may also need to do an ifftshift
on the result to get the quadrants back in the right place.
Use imshow to display the result.
Save this "filtered" image.
Does the operation have the intended result?
How do the borders compare to a version created using conv2?
C. Other Filters
The Gaussian smooths images, but there are other filters with different
properties. For instance, the so-called "Laplacian of [the]
Gaussian" or LoG filter:
LoG(x,y) = -(1-(x2+y2)/2) g(x,y)
Using the functional form given above, create a matrix containing
the 2-D LoG with the same x and y domains used above.
Display your LoG kernel using both imshow
and mesh. Save one of these images.
As a filter, what types of structures would you
expect the LoG to detect?
Take the Fourier transform of the LoG.
Use imshow to display the (shifted and
log compressed) magnitude of the LoG's transform. Save this image
using print.
What effect do you expect the LoG to have
on the low, mid, and high frequencies?
Take the componentwise product of the cameraman and LoG kernel transforms.
Take the inverse Fourier transform with ifft2. You'll likely
need to extract only the real component (using the command real),
and you may also need to do an ifftshift on the result to
get the quadrants back in the right place.
Use imshow to display the result (the
LoG is not an averaging filter, so you'll have to relax the bounds
on the display). Save this image using print.
Where are the responses the strongest? Does it
match your predictions?
Note, if you are unsure, you can verify your result by using conv2
on the original image and the LoG kernel.
D. Box Filter
Create a 256×256 kernel of zeros.
Makes the first 10 rows and columns of your kernel a uniform box filter.
Don't forget to normalize!
Take the Fourier transform of your box filter kernel.
Use imshow to display the (shifted and log compressed) magnitude
of the box filter's transform. You may wish to add false color using
a color map to more easily see the differences in magnitudes. The
command
colormap(jet)
renders the grayscale values as indices into a colormap that ranges
from cool to warm colors.
Save your image using print.
Is the result "isotropic?" (That
is, is it the same in all directions?) How does its elimination of
high frequencies compare to the Gaussian?
Why might we avoid smoothing with the
box filter before downsampling?