Skip to content

Labwork 2

Problem 1: Fourier transform interpretation

FFT_sample1.ics and FFT_sample2.ics are the Fourier transforms of two images.

Load these Fourier transform images and execute the tasks below:

  • Display the Fourier Transformations and determine the spatial frequencies m_1,m_2 corresponding to the visible peaks (you can find the peaks by hand from the image, no need to do this automatically) % TODO1
  • What is be the maximum spatial frequency m_{max} possible to represent in an image of size N\times N for e.g. N=256 pixel? Does the image size matter in terms of frequency in pixel units? Generate such an image using the function cos(2*pi*m/N*xx([N N],’true’)) and inspect its Fourier transformation. NB: the dipimage function xx generates a ramp in the x-direction from -N/2 to +N/2 over N pixels % TODO2
  • Generate spatial images from the estimated peak positions again via cosine functions and compare them with inverse Fourier transform of the images. Do they match? % TODO3 If not, how could you know that the wave in the images m_1,m_2 are sine or cosine functions?
  • Conservation of energy of the Fourier transformation (Parseval relation): Check that

    \sum_{x,y} |i(x,y)|^2 = \sum_{u,v} |\hat{i}(u,v)|^2

    is valid (for an arbitrary grey-value input image). Think about the normalization factor. % TODO4

Comparing images

To check if two images are the same, best to divide them by each other. This is better than to subtract them from each other, as it gives you relative information independent of the actual grey values in the images.

Inverse Fourier Transform

If you apply ift(ft(a)) with a a real input image, you expect that the output is also real. That is not the case! Due to numerical rounding errors, the output will have a (small) imaginary part. To display the images use the mapping “real part” or just real(ift(....

Relation to Discrete Fourier Transformation in the Lectures
\hat{g}(u,v) = \frac{1}{N} \sum_{x,y} g(x,y) e^{-j\frac{2\pi}{N} (ux+vy)}

The frequency m corresponds to the variable u or v depending on the dimensionality of the signal. Here you see that N is the period of the function, here the width of the image, and that the discrete Fourier Transformation is periodic with 2\pi:\ \hat{g}(u,v)=\hat{g}(u+2\pi,v+2\pi). The math is the same as for a Fourier Series in fact! With fundamental frequency \Omega_0=\frac{2\pi}{N}. The unit of the spatial frequency is [1/length] if the unit of the pixel is [length]. Typically the pixel size is given in meters, then the spatial frequency is in 1/meters.

Problem 2: Fourier filtering

Fourier filtering is one of the most common image processing operations. Mathematically the transfer function of the filter is multiplied by the Fourier transformation of the input

\hat{o} = \hat{i} \cdot \hat{h}

in which hat \hat{\cdot} denotes the Fourier transformation, o the output image, i the input image and \hat{h} the transfer function of the filter. This operation corresponds in the spatial domain to convolution of the filter with the input.

  • Create a low-pass filter with a hard cut-off and one with a soft cut-off % TODO5 in the Fourier domain use it to filter the input image in the Fourier domain. The hard cut-off can be realized with rr(imsize(in))<value to generate a pill-box. The dipimage function rr is similar to xx but with a radial coordinate. What is the difference between hard and soft filtering on the output images (assuming the footprint in the Fourier domain is about the same)? Is the outcome different when you scale the filter \hat{h} (e.g. by normalizing it)?
  • A high-pass filter can be created in the Fourier domain by \hat{h}_{high}=1-\hat{h}_{low}. Implement a high-pass filter and check that a corresponding high and low-pass filtered images sum up to the original image %TODO6.

Files

You need to download the following scripts and images for this labwork.


Last update: 2023-02-23