# Assignment

Computing Skills Assignment Help

Rating:

# MATLAB Assignment Help

## Overview

This assignment will give you some hands-on experience with image transformations, interpolation and frequency space filtering in MATLAB. This covers material from weeks 4 to 6. In this assignment work, you will be required to modify two functions that implement a projective transformation and a modified form of the Wiener deblur function presented in class.

### IMPORTANT

Only the following routines from the image processing toolbox may be used for testing purposes: imshow imnoise imfilter. Using other routines from the image processing toolbox (unless part of the test scripts or approved in class/tutorials) may result in zero marks for that component of the assignment work.

### Assignment Submission

Assignments are to be submitted via MyUni as a ZIP archive file containing the five key MATLAB functions and a Word or PDF document summarising your results with comments on the performance of the processing steps employed.

## Exercise 2A – (5%) – Image Registration & Re-sampling

You have been asked to complete a piece of software for registering two images. The software is designed to allow a user to select control points in two images. These points are then used to estimate an affine transformation between the two images and then apply the image transformation to the first images. Unfortunately, two key components remain to be written. The first takes two sets of control points P1 and P2 for image 1 and 2 respectively and estimates an affine transformation T which maps points in image 1 onto points in image 2. The second missing component takes image 1 and the transformation T and reprojects it into the same view as image 2.

STEP 1: Modify the supplied M-file calc_affine,m which takes two Nx2 arrays of control points P1 and P2 and estimates the 3x3 affine transformation:

(see the “Hints/Advice” section for clues as to how to solve the above for a,b,c,d,e and f) The script calc_affine_test.m can be used to check your code is working.

STEP 2:

Modify the supplied M-file transform_image.m which given an affine transformation matrix returns a transformed version of the supplied image I. For simplicity the function can use simple “nearest neighbour” interpolation as described in lectures. This can be achieved by:-

1. Compute the inverse of the transform T

2. For each pixel in the output image

a. use the inverse of T to compute the pixel location in the original image.

b. Round this to find the nearest pixel.

c. If the coordinate is inside the image use the pixels value for the output image otherwise set the output pixel to zero.

By computing the mapping from the output image back to the input image we ensure each pixel in the output can be easily assigned a vale. For simplicities sake, the output image should be same size as the input image and the top left corner represent coordinate (0,0). Set any pixels not described by the transformation to zero (ie. black). For example:

should produce an image like that shown here → In the above code fragment, the pixel (x=1,y=1) maps to approx (x=1.25, y=20.58) or (row=20.58, column=1.25).

Use the provided test function tform_test to check your work. The results of this test file on a working solution are shown below.

Experiment with the code on other imagery of your choice and write up your results.

• You can make use of the MATLAB functions inv() and round().

• The linear equations can also be written in the classic form Ax=b, where x is the column vector [a,b,c,d,e,f], A is a matrix of the x,y and z values and b is a column vector of the x’,y’,z’ values.

• MATLAB has a shorthand notation for solving linear equations of the form Ax=b which can be written as b=Ax. where A is a matrix and b and x column vectors. Use this shorthand to calculate the coefficients of the transformation T in calc_affine.m. This makes it much easier to complete STEP 1.

• To construct the new image in ‘transform_image.m’ we take the inverse of the matrix T (use the inv() function to do this) and use this to compute the transformation of every pixel in the output image back into the original image. This should readily identify pixels lying outside of the original image and provide you with information about the nearest pixel in the original image.

• Check for black-spots, ‘holes’ or regular patterns in the original image. These are signs that you have an your output image that were not in error in your code.

• If the image rotation looks like it is around the wrong way remember that MATLAB indexes arrays in (row,column) order and not in (x,y) order as used in the transformation T.

## Exercise 2B – (4 %) – Butterworth Filter

Here we will implement a version of the Butterworth filter described in lectures.

Modify the function fft_filter() such that given and image I and a set of FFT filter coefficients B (where the coefficients are shifted such that the array centre represents zero frequency) the function returns the FFT filtered version of image I. That is:

I2 = fft_filter(I,B);

Use the functions fft2(), ifft2(), real(), fftshift(), ifftshift() and meshgrid() to achieve this.

Once completed, modify the function butterworth() such that this function returns a set of FFT filter coefficients representing the Butterworth filter discussed in class. The function butterworth() is called as follows:

B = butterworth(width, height, order, cutoff, x0,y0)

Where width and height refer to the size of the filter, order and cutoff are the filter order and frequency cut-off. The values x0 and y0 are offsets of the Butterworth filter relative to zero frequency. If not supplied x0 and y0 both default to zero. The expression for the Butterworth filter weights (in the Fourier domain) is as follows:

Where n and are the order and filter cut-off values and xo and yo are offsets from the centre Note that x and y are relative to zero frequency (ie DC). Once both functions are completed, test your code using the script butter_test.m. Experiment with different images and filter settings and write up your results in your report.

## Exercise 2C – (6%) – Wiener Image De-blurring in the presence of noise and interference

In class, we described the Wiener filter for de-blurring as follows:

Where Fb was the FFT of the blurring (aka. point spread), and Sn and Ss are the spectrums of the noise/interference and the "pure" image respectively. In practice it is frequently not possible to obtain a measurement of the spectrum of the "pure" image. However we may have a sample of the noise/interference in addition to the corrupted image and the point spread function estimate of the blurring process. For this assignment we will approximate the spectrum of the "pure" image using by subtracting the spectrum of the noise estimate from the spectrum of the noisy image. That is:

where FI is the FFT of the noisy image and Fn is the FFT of the noise sample we have (ideally this estimate would be constructed from several samples, but for this exercise we will use only one). To further insure stability, we will also assume there is a minimum level of noise in the sampled data across all frequencies (even if it is not measured in the single sample we have - recall that white noise is spectrally flat) that is the final expression is:

where the constant k is the assumed minimum level of uniform noise in the system.

In this exercise you will be required to modify the supplied function wiener_noisy_deblur.m such that given a noisy blurred image, the blurring filter, and a sample image noise estimate, your solution implements the above filter and applies it to the supplied noisy image data. It is suggested you make use of functions such as fft2(), ifft2(), padarray(), circshift(), real(), imag(), max() and expressions containing .* and . (the element by element multiply and divide operations). The constant eps can also be used to avoid division by zero. You may also use fftshift() etc to help display your intermediate estimates but please note fftshift-ing is not required to solve this problem. The initial step of smoothing the boundary of the image to prevent ringing at the edges of the image (as shown in class) has been done for you using MATLAB's edgetaper() function.

### Suggested steps:

1. construct frequency domain estimates of Fi and Fn from the supplied corrupted image and noise sample (reminder: use the edgetaper()'ed version of I).

2. estimate the expression max(k, Fn 2 /(FI 2 − Fn 2 )) using your calculations from step 1. A suitable value for the k is 1e-10 times the number of pixels in I. You may also want to ensure the bottom half of the expression is > 0 in case the noise spectrum is accidentally greater than the noisy image spectrum (this shouldn’t normally happen but just in case…).

3. Construct an estimate of Fb from B. Note that the blurring function B will be smaller that the image so you will need to pad this image to make it the same size as I otherwise Fb will have too few coefficients. How you pad this will affect the spatial delay (shift) of the resulting image output so you will need to consider this otherwise you will get an incorrect result.

4. Using the calculations from steps 1 to 3 implement the remainder of the expression to come up with the inverse filter Finv. Be careful with division by zero!

5. Apply this filter (ie. multiply the coefficients) to Fi to reconstruct the FFT description of the reconstructed image and then convert back to the spatial domain. If the imaginary component of the reconstruction is large this may indicate an error in your calculations...

6. If there is any remaining shift error in your result (see comments for step 3) then fix it now.Depending on how you have solved the above, you may also want to consider limiting the output image data to the range 0..1.

The function wiener_test.m has been supplied for testing. Experiment with different imagery and noises and write up your results.

### IMPORTANT NOTE:

do not expect amazing results from your filter, this example has been designed to be reasonably realistic. The edge border effects despite bring reduced by the edgepatep() function are not fully suppressed.

Above: two examples of the Wiener de-blur function applied to test imagery (see wiener_test.m). Note the recovered results are not as good(sharp) as the original imagery and contain minor artefacts. The second example contains both noise and a sinusoidal interference pattern in addition to a larger blurring process.

## Exercise 2D – (3%) – Written Questions

#### • 2D.1 (1%)

a) In terms of the simple linear transformation’s ‘translation’, ‘isometric’, ‘linear conformal’, ‘affine’ and ‘projective’.

Which transformation best describes the relationships between images for an overhead camera looking straight down and observing magazines moving along a conveyor belt below. The camera can only see the magazines on the conveyor and not the surrounding area.

If the camera was not looking straight down, but was say angled at 45 degrees to the conveyor would this change the projection and if so what would it now be?

b) Assuming the following represents a ‘linear conformal’ transformation, what is the underlying translation, rotation angle and scale of this transformation? (assume points are of the form [x,y,1])

0.2397 − 0.438820

T = 0.4388 0.2397 −5

0 0 1

### • 2D.2 (0.5%)

Bilinear interpolation uses a 2x2 patch of image data to estimate pixel values after a transformation has been applied. If the 2x2 patch of an image for coordinates (20,10) to (21,11) is given by the greylevel values:

128   64

64    32

What are the nearest and bilinear estimate for pixel (20.6, 10.2) ?

### • 2D.3 (0.5%)

In JPEG compression using 8x8 blocks of DCT values. Why are the DCT values extracted in a zig-zag fashion before being Huffman encoded?

### • 2D.4 (1%)

An image has been processed by 3 different, but unknown, filters. The log magnitude spectrum of the 3 filters is given below. Look carefully at each of the spectrums and the output images (see overleaf). Match the spectrums of the filters (1,2 and 3) to the image (A,B or C) which most closely resembles its likely output. Make sure you explain the reasoning for each of your choices.

#### Details

• Number of views:
596
• PRICE :
AU\$ 101.00

BROWSE

### Our Top Experts

Holding a PhD degree in Finance, Dr. John Adams is experienced in assisting students who are in dire need...

55 - Completed Orders

Canada, Toronto I have acquired my degree from Campion College at the University of Regina Occuption/Desi...

52 - Completed Orders

Even since I was a student in Italy I had a passion for languages, in fact I love teaching Italian, and I...

102 - Completed Orders

To work with an organization where I can optimally utilize my knowledge and skills for meeting challenges...

109 - Completed Orders

JOB OBJECTIVE Seeking entry level assignments in Marketing & Business Development with an organization...

202 - Completed Orders

Current work profile Project manager- The Researchers Hub (2nd Jan 2016 to presently working) Researc...

20 - Completed Orders

Sales Assistant, Mito Marina Assigned to the Stationery dept – assisted in merchandising, stock taking...

100 - Completed Orders

Personal Profile Dedicated and highly experienced private chauffeur. High energy, hardworking, punctua...

200 - Completed Orders