Sei sulla pagina 1di 10

Lab Review 02

Filtering Operations
Image Analysis and Computer Vision
November 11, 2013
Two-dimensional Fourier transform, understanding of its properties and test these properties in
practice
How to use Fourier transform on image data, expressed spatially or in the Fourier domain
How different smoothing operations are influenced by various kinds of noise and how contrast
sharpening can be performed in practice
An understanding of how multiple linear operations can be combined into a composite linear
operation
The relation between the continuous and discrete Fourier transform and test how continuous
filters can be discretized spatially as well as in the Fourier domain
Practical experience of differences between synthetic and real data

=====================================================================
Question 1: Repeat this exercise with the coordinates p and q set to (9, 5), (17, 9), (17, 121), (5, 1)
and (125, 1) respectively. What do you see? Explain?
Fftwavetemplate(p,q,size)
We see that the inverse fourier transformation gives a periodic patterns in the spatial domain. SO
conversely, we can say that the fourier transform of a periodic pattern in the spatial domain is just
presented by the one point in the frequency domain which is the magnitude of the fourier transform.
The point corresponds to the frequency of the stripes in the spatial domain.
The point (9, 5) in the frequency domain presents the changes of the image intensity in the spatial
domain. As it changes the most in the right diagonal direction, so the periodic patterns are left diagonal.
The image intensity changes in the spatial domain changes the most if we go along horizontally,
vertically, and diagonally.
So we see that the fourier transform is change of a basis function, from discrete delta functions defined
in on the Cartesian image domain to complex exponential function with maximum spatial extension.
The basis vector is given by the index (p, q).
The origin (u, v) in the frequency domain is at the corner and in the translated frequency domain the
origin (u, v) is shifted at the middle.

The interval in the frequency domain defined in [0, N-1], but the position in the marix starts from (1, 1).
So we need to subtract 1.
Frequency spectrum displayed in rectangular form (as the real and imaginary parts).
Frequency spectrum displayed in polar form (as the magnitude and phase).
Frequency spectrum displayed in polar form with the spectrum shifted to place zero frequency at the
center.
F(u,0)is related to the frequency u of sinusoids occurring parallel to the x axis of the image.
F(0, v)is related to the frequency v of sinusoids occurring parallel to the y axis of the image.
F(u, v)is related to the frequency u**2+v**2 of sinusoids parallel to a line from the origin to (u, v).
=====================================================================================
Spatial frequency:
The spatial frequency of an image refers to the rate at which the pixel intensities change. The easiest way
to determine the frequency composition of signals is to inspect that signal in the frequency domain. The
frequency domain shows the magnitude of different frequency components.
Fourier transformation:
The Fourier Transform is an important image processing tool which is used to decompose an image into
its sine and cosine components. The output of the transformation represents the image in
the Fourier or frequency domain, while the input image is the spatial domain equivalent. In the Fourier
domain image, each point represents a particular frequency contained in the spatial domain image. The
Fourier Transform is used in a wide range of applications, such as image analysis, image filtering, image
reconstruction and image compression.
The Fourier Transform produces a complex number valued output image which can be displayed with
two images, either with the real and imaginary part or with magnitude and phase. In image processing ,
often only the magnitude of the Fourier Transform is displayed, as it contains most of the information of
the geometric structure of the spatial domain image.
However, if we want to re-transform the Fourier image into the correct spatial domain after some
processing in the frequency domain, we must make sure to preserve both magnitude and phase of the
Fourier image.
The Fourier domain image has a much greater range than the image in the spatial domain. Hence, to be
sufficiently accurate, its values are usually calculated and stored in float values.
The Fourier Transform is used if we want to access the geometric characteristics of a spatial domain
image. Because the image in the Fourier domain is decomposed into its sinusoidal components, it is easy

to examine or process certain frequencies of the image, thus influencing the geometric structure in the
spatial domain.
If an image represented in frequency space has high frequencies then it means that the image has sharp
edges or details. The low frequency terms are on the center of the square, and terms with higher
magnitude are on the outer edges. (Imagine an invisible axis with its origin at the center of the square.)
Frequency domain offers some attractive advantages for image processing. It makes large ltering
operations much faster, and it collects information together in different ways that can sometimes separate
signal from noise or allow measurements that would be very difficult in spatial domain. Furthermore, the
Fourier transform makes it easy to go forwards and backwards from the spatial domain to the frequency
space.
===========================================================================
Question 2: Explain and illustrate with a Matlab figure how a position (p, q) in the Fourier domain
will be projected as a sine wave in the spatial domain.
lab2_ex2(64,64)
In the Fourier domain image, each point represents a particular frequency contained in the spatial domain
image.
Each pair of points in the frequency domain corresponds to a sinusoid in the spatial domain.
The point (u, v) in the frequency domain corresponds to the basis function with frequency u in x and
frequency v in y.
The frequency space on the image consists of higher frequencies as well as low ones, means that the
original image has sharp edges. If the image has lower frequency means the image has not sharp edges.
Another thing to note is that if an image has perfectly sinusoidal variations in brightness, then it can be
represented by very few dots on the frequency image. From those images, you can also see that regular
images or images of repeating pattern generate fewer dots on the frequency graph.
Since the images contain only distinct frequencies, the Fourier images contain only dots, i.e., have nonzero values only at specic locations.
Since the coordinates of the dots equal the frequencies of the sinusoids occurring in the original image,
higher image frequencies cause the dots to move away from the origin.
The dots are oriented from the origin in the same direction as the frequency wave in the original image.
If we rotate the image (e.g., consider the rst and second rows), the Fourier transform rotates with it.
The dots are oriented in the direction of the waves, so perpendicular to the edges occurring in the original
image.

We also see star like patterns in FT due to aliasing artifacts.

===========================================================================
The spatial frequency is the frequency across space (the x-axis in this case) with which the brightness
modulates.
The magnitude of the sinusoid corresponds to its contrast, or the difference between the darkest and
brightest peaks of the image. A negative magnitude represents a contrast-reversal, i.e. the brights become
dark, and vice-versa. The phase represents how the wave is shifted relative to the origin, in this case it
represents how much the sinusoid is shifted left or right.
You can imagine that the white parts are top of the wave and black parts are the bottom part in the spatial
domain pictures of the wave form.

===========================================================================
Question 3: How large is the amplitude? Write down the expression derived from Equation (4) in
these notes. Complement the code (variable amplitude) accordingly.
Fabsmax = max(abs(F(:)));

amplitude = Fabsmax;
===========================================================================

========================================================================
Question 4: How does the direction and length of the sine wave depend on p and q? Draw an
illustrative figure on paper. Write down the explicit expression that can be found in the lecture
notes. Complement the code (variable wavelength) accordingly.
lab2_ex2(64,64)

========================================================================
Question 5: What happens when we pass the point in the center and either p or q exceeds half the
image size? Explain and illustrate graphically with Matlab!
lab2_ex5(64,64)
The image shows a sinusoidal image with less brightness and higher spatial frequency.
We pass the point in the centre to show the centered FFT as it is a periodic function. In the centered
image the centre point represents the 0 frequency.
========================================================================

Question 6: What is the purpose of the instructions following the question what is done by these
instructions? In the code?
This means to change the origin after using fft2. It finds the place with respect to the changed origin for a
shifting fft2.
===========================================================================

Linearity
fftshift:
Y = fftshift(X) rearranges the outputs of fft, fft2, and fftn by moving the zero-frequency component to the
center of the array. It is useful for visualizing a Fourier transform with the zero-frequency component in
the middle of the spectrum. For vectors, fftshift(X) swaps the left and right halves of X. For matrices,
fftshift(X) swaps the first quadrant with the third and the second quadrant with the fourth.
ExamplesFor any matrix X Y = fft2(X)
has Y(1,1) = sum(sum(X)); the zero-frequency component of the signal is in the upper-left corner of the
two-dimensional FFT. For Z = fftshift(Y) this zero-frequency component is near the center of the matrix.

===========================================================================
Question 7: Why are these Fourier spectra concentrated to the borders of the images?
lab2_ex7()
lab2_ex7_split_1()
F(u,0)is related to the frequency u of sinusoids occurring parallel to the x axis of the image.
F(0, v)is related to the frequency v of sinusoids occurring parallel to the y axis of the image.
F(u, v)is related to the frequency u^2+v^2 of sinusoids parallel to a line from the origin to (u, v).
Since the coordinates of the dots equal the frequencies of the sinusoids occurring in the original image,
higher image frequencies cause the dots to move away from the origin.
===========================================================================
Question 8: Why is the logarithm function applied?
Typically, the values of |F(u, v)| are such that direct display of these values results in dark, low-contrast
images. To enhance contrast, log(|F(u, v)| + 1) (or a similar remapping of |F(u, v)|) is often displayed
instead.
The logarithmic transformation of the fourier transform shows that the image contains minor frequencies.
===========================================================================
It is also common to display |F(u, v)| for negative values of u and v. For this, the
origin of the image is shifted to the image center
===========================================================================
Question 9: What conclusions can be drawn regarding linearity?
We can add two functions (images) or rescale a function, either before or after computing the Fourier
transform. It leads to the same result.
However, the logarithmic scaling makes it difficult to tell the influence of single frequencies in the
original image. To find the the most important frequencies we threshold the original fourier magnitude
image.
===========================================================================

Multiplication
===========================================================================
Question 10: Are there any other ways to compute the last image? Remember what multiplication
in Fourier domain equals to in the spatial domain !!
lab2_ex8()
Multiplication in the spatial domain is same as convolution in the fourier domain or vice versa.
Fourier transformation of a convolution is the point wise product of the fourier transformation.
===========================================================================
Scaling

===========================================================================
Question 11: What conclusions can be drawn from comparing the results with those in the previous
exercise?
lab2_ex11()
Compression in the spatial domain is same as the expansion in the fourier domain and vice versa.
i.e. the dimensions of the box have inverse relation with the pattern of the fourier spectrum. If the width is
increased, the corresponding fourier pattern gets narrower and denser.
So we get the centered log transformation.
===========================================================================
Rotation
===========================================================================
Question 12: What can be said about possible similarities and differences?
L2_12ex()
Same as the original image but rotate 30 degree like the original. One of the properties of the 2D FT is
that if you rotate the image, the spectrum will rotate in the same direction:

===========================================================================
Rotational symmetry
===========================================================================
Question 13: How does the rotational symmetry affect the Fourier spectrum and why?
L2_13ex()
The Fourier Transform is rotationally invariant.
The fft of the circle image is also a circular pattern. It is like a summation of box function rotated in every
angle, so the corresponding fourier spectrum is also the summation of the individual patterns which looks
like the circular one.
===========================================================================
Translation
===========================================================================
Question 14: What similarities and differences can you observe?
L2_14ex()
Similar into the centered fourier transform but differences into the phase spectrum.
===========================================================================
Information in Fourier phase and magnitude
===========================================================================
Question 15: What information is contained in the phase and in the magnitude of the Fourier
transform?

Phone = phonecalc128;
L2_15ex(inpic)
pow2image() for different magnitude using power spectrum and randphaseimage() that keeps the
magnitude of the fourier distribution but replaces the phase information with a random distribution.
Phase contains most of the position information of the image (power is changed but still the images are
recognizable for the phase) and the magnitude contains some information about grey levels.
===========================================================================
Gaussian convolution implemented via FFT
Gaussian convolution means that we convolve the image with a Gaussian kernel.
With spatial discretization and spatial convolution:
1. Generate a filter based on a sampled version of the Gaussian function.
2. Convolve the image with this filter using the embedded Matlab-function conv2.
With spatial discretization and convolution via FFT:
1. Generate a filter based on a samples version of the Gaussian function.
2. Fourier transform the original image and the Gaussian filter.
3. Multiply the Fourier transforms.
4. Invert the resulting Fourier transform.
Gaussian convolution in the Fourier domain:
1. Fourier transform the original image
2. Multiply the transformed image with the Fourier transform of the Gaussian kernel.
3. Invert the resulting Fourier transform.
===========================================================================
spat_filter = gaussffta(phone,10); this function uses: gauss = l_p_filter_sp(m, n, sigma);
four_filter = gaussfftb(phone,10); this function uses: H = low_pass_filter(type, M, N, D0, n)
pixels = discgaussfft(inpic, sigma2)

===========================================================================
Question 16: How does the result correspond to the ideal continuous case, for which the covariance
matrix is t multiplied by the identity matrix?
L2_16ex_1(t)
Or,
V = L2_17ex(0.1 or 1 or 10 or 100)
We calculate the impulse response, so the variance is just what was given input.
We get the covariance matrix which is an identity matrix multiplied by t.

===========================================================================
Question 17: Show the impulse response and variance for the above mentioned t-values. What are
the variances of your discretized Gaussian kernel for t = 0.1, 1.0, 10.0 and 100.0?
L2_16ex(phone,0.1)
===========================================================================
===========================================================================
Question 18: Can you note any differences between the results of gaussffta and gaussfftb? Why are
the results different from or similar to the estimated variance? Lead: First consider the results for
small t values.
L2_18ex_1(Phone,0.1)
I have not found that much different but a little in the variance. And that may be because of filter in
different way.
===========================================================================
Question 19: Convolve a couple of images with Gaussian functions of different variances (like t =
1.0, 4.0, 16.0, 64.0 and 256.0). What effects can you observe?
L2_18ex_1(Phone,0.1)
The images getting blurred with t.
===========================================================================
Smoothing
L2_18ex(office)
===========================================================================
Question 20: What conclusions can you draw from comparing the results of the respective method?
L2_19ex(phone)
L2_20ex(phone)
L2_21ex(phone)
L2_22ex(phone)
By filters, we change in image intensity also change in amount of noise. Gaussian filter is comparatively
better for removing Gaussian noise, but it blurs the image.
The amount of noise removal and amount of blurring increases as t increases.
Median filter works well specially for removing sap noise.
Ideal low pass filter creates a ringing effect for both add and sap, where the ring size increases as the cutoff frequency decreases. It can be useful to see the effects of high frequencies in the image.
===========================================================================
Question 21: What positive and negative effects does each filter type have?
L2_19ex(phone)
L2_20ex(phone)
L2_21ex(phone)
L2_22ex(phone)
===========================================================================

Question 22: What respective similarities and differences can you observe between the different
filters?
L2_19ex(phone)
L2_20ex(phone)
L2_21ex(phone)
L2_22ex(phone)

===========================================================================
Question 23: How do the results depend on the filter parameters?
L2_19ex(phone)
L2_20ex(phone)
L2_21ex(phone)
L2_22ex(phone)

===========================================================================
Question 24: What are the effects you observe based on these illustrations?
L2_19ex(phone)
L2_20ex(phone)
L2_21ex(phone)
L2_22ex(phone)
===========================================================================
Contrast improvement
===========================================================================
Question 25: Why can you replace the whole operation above with a single filter?
Blocks = blocks1;
sharpmask = L2_ex25(blocks);
filtered image = image coeef * lapalace * image
= (1- coeff*laplace)*image
we made the function sharpmask , so now we can use this function.
===========================================================================
Question 26: How is the Laplace operator affected by noise?
L2_ex26(blocks)
L2_ex27(blocks)
It enhances the noise, because noise is sharp change in the pixel intensity.
===========================================================================

Potrebbero piacerti anche