Lab: Fourier Transforms (2)
CSC 262 - Computer Vision - Weinman
- Summary:
- In this lab you will examine the filtering properties
of some common kernels in the frequency domain.
Deliverables
- The Matlab script used to make your comparisons and generate your
report
- (5 points) Comparison of Gaussian and its FFT (A.7,
A.8)
- (10 points) FFT of tree and Gaussian (B.4, B.5)
- (5 points) Product of transforms (B.7)
- (5 points) Frequency observations (B.8)
- (10 points) Inverted product (B.10)
- (10 points) Inverted product observations (B.11)
- (5 points) LoG kernel (C.2)
- (5 points) LoG FFT magnitude (C.5)
- (5 points) LoG frequency observations (C.6).
- (5 points) LoG filter responses (C.9)
- (5 points) LoG kernel detection predictions and observations (C.3,
C.10)
- (5 points) Box filter FFT magnitude (D.4)
- (10 points) Box filter observations and commentary (D.5,
D.6)
- (5 points) FFT-based box filtered image (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.
-
[xx,yy] = meshgrid( linspace(-20,20,256), linspace(-20,20,256) );
- Using its functional form,
create a matrix containing a 2-dimensional Gaussian with a variance
of 1 using the domains for x and y you created above.
Remember that your powers should be component-wise!
- 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 shapes of the two mesh plots
compare? 1
-
What is the largest magnitude in the
FFT of the Gaussian kernel matrix? Why?
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 an image of my Peanuts-esque2 holiday decoration
-
/home/weinman/courses/CSC262/images/tree.png
- Convert this image from a uint8 image to a double
(so that the largest value can be 1).
- Take the Fourier transform of the tree.
-
Use imshow to display the (shifted
and log compressed) magnitude of the tree transform.
-
Use imshow to display the (shifted
and log compressed) magnitude of the Gaussian kernel transform.
- Take the component-wise product of the tree and Gaussian kernel transforms
(both unshifted).
-
Use imshow to display the (shifted and
log compressed) magnitude of the product.
-
What effect does this product have on
the low and high frequencies, respectively?
- Take the inverse Fourier transform of the product with ifft2.
You will 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 "filtered"
image result.
-
Does the operation have the intended effect?
How do the borders compare to a version created using conv2?
What other artifacts can you see? What causes these differences?
C. Other Filters
The Gaussian kernel 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.
Remember that your powers and multiplication should be component-wise!
-
Display your LoG kernel using both imshow
and mesh.
-
As a spatial filter, what types of structures
would you expect the LoG to detect? (As you did with the "t" in
the image filtering lab.)
- Take the Fourier transform of the LoG.
-
Use imshow to display the (shifted and
log compressed) magnitude of the LoG's transform.
-
Based on the LoG's FFT, what effect do you
expect the LoG to have on the low, mid, and high frequencies?
- Take the component-wise product of the tree 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).
-
Where are the responses the strongest (whether
high or low)? 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.
- Make 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.
-
Is the result "isotropic?" (That
is, is it the same in all directions?) How does its elimination of
high frequencies compare to the transformed Gaussian?
-
Why might we avoid smoothing with the
box filter before downsampling?
-
Visualize the tree image filtered by the
box filter to (partially) support your explanation.
The
tree image was captured by Jerod Weinman (as a graduate
student) and is Copyright 2006, licensed under a
Creative
Commons Attribution-Noncommercial-Share Alike 4.0 International License.
Footnotes:
1After you've reflected on this, but not before, you may want to have
a look at Wolfram's Mathworld brief entry on the
Fourier
Transform of a Gaussian.
2See
A Charlie
Brown Christmas