CS 7321 Winter 1998
PS#2 Solutions by Rob Orr
Images and Spatial Properties
Index
How I solved it
- First I created the initial image (a) in the handout (3 black bars
on a white background)
- I used the Matlab built-in functions ones() and zeros()
- Then I computed the FFT of (a) to generate the power spectrum (d);
to this I:
- wrote a function that squares the in put matrix element by element
(I was unclear about the difference between the "^" and ".^"
operators in Matlab--my function verified their operations); see rjoSquare.m
below
- transformed to frequency using fft2()
- squared the real and imaginary parts separately and added them
- did an fftshift() on the resulting image to transform the FFT into
polar coords.
- took 2 logs to transform the contrast to a usable range
- To generate (b), I high-pass filtered the image in the frequency domain,
convert the image back to the image domain, and rotate the image.
- To high-pass the image, I created a function (rjoCircle.m below) that
creates circular masks anywhere in an arbitrary sized image.
- I created a mask which removes the 'center' of the image in frequency
space and multiplied the image in frequency space by this mask. I needed
to use fftshift() twice in this process.
- Then I converted the image back to image space using ifft2().
- The rotation was accomplished with the imrotate() function.
- To generate (e), I simply computed the fft of (b)
- use fft2() to transform into frequency space
- compute power spectrum in the same was as in (d) (see above)
- To generate (c), I low-passed (a) in a similar way to (b):
- I created a mask that leaves the center and removes the outer part
of the image in frequency space, and then myultiplied the image in frequency
space by this mask. Again, I used fftshift() twice in this process.
- Convert back to image domain by using ifft2().
- The last image, (f), was generated by taking the fft of (c)
- I used fft2() to convert to freq. domain
- I computed power spectrum as in (d)
- I enlarged the image by a factor of 2 and copped out the middle
- I then inverted and adjusted the colormap to show the results a little
better
to TOP
Assumptions and Weaknesses
I made the following assumptions:
- High-pass filtering and low-pass filtering should be done in the frequency
domain
- Matlab would be easy to use
I think the major weakness of my solutions are:
- I didn't generalize my scipt so that it could take an arbitrary input
image
- Low-pass filtering could have been performed more easily by using a
simple Gaussian filter in the image domain
- Simple edge-detection could have been substituted for high-pass filtering
Improvements and Possible Future Work
I think that this can be improved by doing the following
- generalize the script to take arbitrary input images
- play with Gaussian low-pass filtering and edge-detection and see what
kind of images are generated
Results
Panel (a):

Panel (d): the power spectrum of (a).

Panel (b): this is (a) high-pass filtered and rotated 30 degrees clockwise

Panel (e): the power spectrum of (b).

Panel (c): low-pass of (a).

Panel (f): the power spectrum of (c).

What I Learned
How to transform an image from image space into frequency space in
Matlab
The intricacies of computing the power spectrum
What the various parts of the power spectrum image correspond to (high
frequencues vs. low frequencies)
How to high-pass filter and low-pass filter an image in frequency space
How to write functions in Matlab
Source Code
- ps2.m
: this is the script showing how the problem solution was arrived at
- rjoSquare.m:
this function squares each value of a matrix
- rjoCircle.m:this
function creates an arbitrary circular mask