lab review 02 for image analysis

Upload: khan-raqib-mahmud

Post on 01-Jun-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Lab Review 02 for image analysis

    1/10

    Lab Review 02Filtering Operations

    Image Analysis and Computer Vision November 11, 2013

    Two-dimensional Fourier transform, understanding of its properties and test these properties in practiceHow to use Fourier transform on image data, expressed spatially or in the Fourier domainHow different smoothing operations are influenced by various kinds of noise and how contrastsharpening can be performed in practiceAn understanding of how multiple linear operations can be combined into a composite linearoperationThe relation between the continuous and discrete Fourier transform and test how continuousfilters can be discretized spatially as well as in the Fourier domainPractical 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. SOconversely, we can say that the fourier transform of a periodic pattern in the spatial domain is justpresented 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 spatialdomain. 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 definedin 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 theorigin (u, v) is shifted at the middle.

  • 8/9/2019 Lab Review 02 for image analysis

    2/10

    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 thecenter.

    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 wayto determine the frequency composition of signals is to inspect that signal in the frequency domain. Thefrequency 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 intoits sine and cosine components. The output of the transformation represents the image inthe 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. TheFourier Transform is used in a wide range of applications, such as image analysis, image filtering, imagereconstruction and image compression.

    The Fourier Transform produces a complex number valued output image which can be displayed withtwo 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 ofthe 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 theFourier image.

    The Fourier domain image has a much greater range than the image in the spatial domain. Hence, to besufficiently 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 domainimage. Because the image in the Fourier domain is decomposed into its sinusoidal components, it is easy

    http://homepages.inf.ed.ac.uk/rbf/HIPR2/freqdom.htmhttp://homepages.inf.ed.ac.uk/rbf/HIPR2/freqdom.htmhttp://homepages.inf.ed.ac.uk/rbf/HIPR2/freqdom.htmhttp://homepages.inf.ed.ac.uk/rbf/HIPR2/spatdom.htmhttp://homepages.inf.ed.ac.uk/rbf/HIPR2/spatdom.htmhttp://homepages.inf.ed.ac.uk/rbf/HIPR2/spatdom.htmhttp://homepages.inf.ed.ac.uk/rbf/HIPR2/spatdom.htmhttp://homepages.inf.ed.ac.uk/rbf/HIPR2/freqdom.htm

  • 8/9/2019 Lab Review 02 for image analysis

    3/10

  • 8/9/2019 Lab Review 02 for image analysis

    4/10

  • 8/9/2019 Lab Review 02 for image analysis

    5/10

    ========================================================================Question 4: How does the direction and length of the sine wave depend on p and q? Draw anillustrative figure on paper. Write down the explicit expression that can be found in the lecturenotes. 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 centeredimage the centre point represents the 0 frequency.

    ========================================================================

    Question 6: What is the purpose of the instructions following the question what is done by theseinstructions? In the code?

    This means to change the origin after using fft2. It finds the place with respect to the changed origin for ashifting fft2.===========================================================================Linearity

    fftshift:

    Y = fftshift(X) rearranges the outputs of fft, fft2, and fftn by moving the zero-frequency component to thecenter of the array. It is useful for visualizing a Fourier transform with the zero-frequency component inthe 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 thetwo-dimensional FFT. For Z = fftshift(Y) this zero-frequency component is near the center of the matrix.

  • 8/9/2019 Lab Review 02 for image analysis

    6/10

    ===========================================================================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-contrastimages. To enhance contrast, log(|F(u, v)| + 1) (or a similar remapping of |F(u, v)|) is often displayedinstead.

    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, theorigin 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 Fouriertransform. It leads to the same result.However, the logarithmic scaling makes it difficult to tell the influence of single frequencies in theoriginal image. To find the the most important frequencies we threshold the original fourier magnitudeimage.===========================================================================Multiplication===========================================================================Question 10: Are there any other ways to compute the last image? Remember what multiplicationin 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

  • 8/9/2019 Lab Review 02 for image analysis

    7/10

    ===========================================================================Question 11: What conclusions can be drawn from comparing the results with those in the previousexercise?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 isincreased, 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 isthat 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 everyangle, so the corresponding fourier spectrum is also the summation of the individual patterns which lookslike 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 Fouriertransform?

  • 8/9/2019 Lab Review 02 for image analysis

    8/10

    Phone = phonecalc128;L2_15ex(inpic)pow2image() for different magnitude using power spectrum and randphaseimage() that keeps themagnitude 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 arerecognizable 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 image2. 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 covariancematrix 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.

  • 8/9/2019 Lab Review 02 for image analysis

    9/10

    ===========================================================================Question 17: Show the impulse response and variance for the above mentioned t-values. What arethe 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 arethe results different from or similar to the estimated variance? Lead: First consider the results forsmall 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 indifferent 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.

    ===========================================================================SmoothingL2_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 cut-off 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)

    ===========================================================================

  • 8/9/2019 Lab Review 02 for image analysis

    10/10

    Question 22: What respective similarities and differences can you observe between the differentfilters?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)*imagewe 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.

    ===========================================================================