skeletons.jpg ghost...mean value for the ghost gray scale image is 212.062. c) create an empty 1200...

7
OPTI 512 Homework 7 Due: November 6, 2019 1. In the spirit of Halloween, we are going to find a ghost using a matched filter. You will need Matlab or something equivalent to do this problem. The images below are called Skeletons.jpg and Ghost.jpg, and can be downloaded from the course website. Do the following to find the ghost in a sea of skeletons: a) Import the file Skeletons.jpg and convert it to gray scale. This should be a 1200 x 1200 pixel array. What is the mean value of the array? Subtract this mean value from the array. We will call this zero-mean skeleton array (, ). I just used the green channel from the image for the gray scale conversion. If the conversion was done differently, the means values might be slightly different. The mean value for the Skeletons gray scale image is 205.684. b) Import the file Ghost.jpg and convert it to gray scale. This should be a 76 x 58 pixel array. What is the mean value of this array? Subtract this mean value from the array.

Upload: others

Post on 26-Sep-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Skeletons.jpg Ghost...mean value for the Ghost gray scale image is 212.062. c) Create an empty 1200 x 1200 pixel array and place the template ๐‘ก๐‘ก(๐‘ฅ๐‘ฅ, ๐‘ฆ๐‘ฆ) in the middle

OPTI 512 Homework 7 Due: November 6, 2019

1. In the spirit of Halloween, we are going to find a ghost using a matched filter. You will

need Matlab or something equivalent to do this problem. The images below are called

Skeletons.jpg and Ghost.jpg, and can be downloaded from the course website.

Do the following to find the ghost in a sea of skeletons:

a) Import the file Skeletons.jpg and convert it to gray scale. This should be a 1200 x

1200 pixel array. What is the mean value of the array? Subtract this mean value

from the array. We will call this zero-mean skeleton array ๐‘ ๐‘ (๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ).

I just used the green channel from the image for the gray scale conversion. If the

conversion was done differently, the means values might be slightly different. The

mean value for the Skeletons gray scale image is 205.684.

b) Import the file Ghost.jpg and convert it to gray scale. This should be a 76 x 58 pixel

array. What is the mean value of this array? Subtract this mean value from the array.

Page 2: Skeletons.jpg Ghost...mean value for the Ghost gray scale image is 212.062. c) Create an empty 1200 x 1200 pixel array and place the template ๐‘ก๐‘ก(๐‘ฅ๐‘ฅ, ๐‘ฆ๐‘ฆ) in the middle

We will call this zero-mean ghost array ๐‘ก๐‘ก(๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ) and use it as the template for the

object we are trying to find in the skeleton array.

I again just used the green channel from the image for the gray scale conversion. If

the conversion was done differently, the means values might be slightly different. The

mean value for the Ghost gray scale image is 212.062.

c) Create an empty 1200 x 1200 pixel array and place the template ๐‘ก๐‘ก(๐‘ฅ๐‘ฅ, ๐‘ฆ๐‘ฆ) in the middle

of the array We will call this array the ghost array ๐‘”๐‘”(๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ). Display this array in your

code to verify that you did it correctly. Save you ink. No need to put it in the

assignment.

d) We now want to find the cross correlation ๐›พ๐›พ๐‘ ๐‘ ๐‘ ๐‘ (๐‘ฅ๐‘ฅ, ๐‘ฆ๐‘ฆ) of the two arrays. This is more

easily done in the Fourier domain. We know that โ„ฑ2๐ท๐ท๏ฟฝ๐›พ๐›พ๐‘ ๐‘ ๐‘ ๐‘ (๐‘ฅ๐‘ฅ, ๐‘ฆ๐‘ฆ)๏ฟฝ = ๐‘†๐‘†(๐œ‰๐œ‰, ๐œ‚๐œ‚)๐บ๐บโˆ—(๐œ‰๐œ‰, ๐œ‚๐œ‚),

where ๐‘†๐‘†(๐œ‰๐œ‰, ๐œ‚๐œ‚) = โ„ฑ2๐ท๐ท{๐‘ ๐‘ (๐‘ฅ๐‘ฅ, ๐‘ฆ๐‘ฆ)} and ๐บ๐บ(๐œ‰๐œ‰, ๐œ‚๐œ‚) = โ„ฑ2๐ท๐ท{๐‘”๐‘”(๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ)}. Knowing this, calculate

the cross correlation as ๐›พ๐›พ๐‘ ๐‘ ๐‘ ๐‘ (๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ) = โ„ฑ2๐ท๐ทโˆ’1๏ฟฝ๐‘†๐‘†(๐œ‰๐œ‰, ๐œ‚๐œ‚)๐บ๐บโˆ—(๐œ‰๐œ‰, ๐œ‚๐œ‚)๏ฟฝ. Plot ๏ฟฝ๐›พ๐›พ๐‘ ๐‘ ๐‘ ๐‘ (๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ)๏ฟฝ.

Page 3: Skeletons.jpg Ghost...mean value for the Ghost gray scale image is 212.062. c) Create an empty 1200 x 1200 pixel array and place the template ๐‘ก๐‘ก(๐‘ฅ๐‘ฅ, ๐‘ฆ๐‘ฆ) in the middle

e) What are the x, y coordinates of the maximum value of ๏ฟฝ๐›พ๐›พ๐‘ ๐‘ ๐‘ ๐‘ (๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ)๏ฟฝ? Verify that the

ghost is indeed located at this location in the original Sketetons.jpg image.

The maximum value of ๏ฟฝ๐›พ๐›พ๐‘ ๐‘ ๐‘ ๐‘ (๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ)๏ฟฝ occurs at the point (1117, 357). Zooming into this

position on the original image shows our ghost.

Page 4: Skeletons.jpg Ghost...mean value for the Ghost gray scale image is 212.062. c) Create an empty 1200 x 1200 pixel array and place the template ๐‘ก๐‘ก(๐‘ฅ๐‘ฅ, ๐‘ฆ๐‘ฆ) in the middle

2. State whether the following functions and band-limited or not. If they are band-limited,

determine the Nyquist frequency.

a) ๐‘Ÿ๐‘Ÿ๐‘Ÿ๐‘Ÿ๐‘Ÿ๐‘Ÿ๐‘ก๐‘ก ๏ฟฝ๐‘ฅ๐‘ฅ3๏ฟฝ

The Fourier transform is 3๐‘ ๐‘ ๐‘ ๐‘ ๐‘ ๐‘ ๐‘Ÿ๐‘Ÿ(3๐œ‰๐œ‰) and the sinc() function has non-zero values out

to infinity, so the function is not band-limited.

b) ๐‘ ๐‘ ๐‘ ๐‘ ๐‘ ๐‘ ๐‘Ÿ๐‘Ÿ ๏ฟฝ๐‘ฅ๐‘ฅ3๏ฟฝ

The Fourier transform is 3๐‘Ÿ๐‘Ÿ๐‘Ÿ๐‘Ÿ๐‘Ÿ๐‘Ÿ๐‘ก๐‘ก(3๐œ‰๐œ‰) which is zero for |๐œ‰๐œ‰| > 16 , so the function is

band-limited and the Nyquist frequency ๐‘๐‘๐œ‰๐œ‰ = 16.

c) ๐บ๐บ๐บ๐บ๐บ๐บ๐‘ ๐‘ (4๐‘ฅ๐‘ฅ)

Page 5: Skeletons.jpg Ghost...mean value for the Ghost gray scale image is 212.062. c) Create an empty 1200 x 1200 pixel array and place the template ๐‘ก๐‘ก(๐‘ฅ๐‘ฅ, ๐‘ฆ๐‘ฆ) in the middle

The Fourier transform is 14๐บ๐บ๐บ๐บ๐บ๐บ๐‘ ๐‘  ๏ฟฝ๐œ‰๐œ‰

4๏ฟฝ which has non-zero values out to infinity, so the

function is not band-limited.

d) ๐‘ก๐‘ก๐‘Ÿ๐‘Ÿ๐‘ ๐‘  ๏ฟฝ๐‘ฅ๐‘ฅ2๏ฟฝ

The Fourier transform is 2๐‘ ๐‘ ๐‘ ๐‘ ๐‘ ๐‘ ๐‘Ÿ๐‘Ÿ2(2๐œ‰๐œ‰) which has non-zero values out to infinity, so the

function is not band-limited.

e) ๐‘ ๐‘ ๐‘ ๐‘ ๐‘ ๐‘ ๐‘Ÿ๐‘Ÿ2 ๏ฟฝ๐‘ฅ๐‘ฅ2๏ฟฝ

The Fourier transform is 2๐‘ก๐‘ก๐‘Ÿ๐‘Ÿ๐‘ ๐‘ (2๐œ‰๐œ‰) which is zero for |๐œ‰๐œ‰| > 12 , so the function is band-

limited and the Nyquist frequency ๐‘๐‘๐œ‰๐œ‰ = 12.

f) ๐›ฟ๐›ฟ(๐‘ฅ๐‘ฅ)

The Fourier transform is 1 which is non-zero values out to infinity, so the function is

not band-limited.

g) ๐‘Ÿ๐‘Ÿ๐‘๐‘๐‘ ๐‘ (5๐œ‹๐œ‹๐‘ฅ๐‘ฅ)

The Fourier transform is

12๏ฟฝ๐›ฟ๐›ฟ ๏ฟฝ๐œ‰๐œ‰ โˆ’

52๏ฟฝ + ๐›ฟ๐›ฟ ๏ฟฝ๐œ‰๐œ‰ +

52๏ฟฝ๏ฟฝ

which is zero for |๐œ‰๐œ‰| > 52 , so the function is band-limited and the Nyquist frequency

๐‘๐‘๐œ‰๐œ‰ = 52.

3. Download the file phase.dat from the course website. You will need Matlab or something

equivalent to do this problem. This is a binary file containing 1024 x 1024 consecutive

double values corresponding to a 1024 x 1024 array of phase values ฮฆ(๐‘ฅ๐‘ฅ, ๐‘ฆ๐‘ฆ). For this

problem, phase contrast techniques will be illustrated. Do the following:

Page 6: Skeletons.jpg Ghost...mean value for the Ghost gray scale image is 212.062. c) Create an empty 1200 x 1200 pixel array and place the template ๐‘ก๐‘ก(๐‘ฅ๐‘ฅ, ๐‘ฆ๐‘ฆ) in the middle

a) Use the following Matlab code snippet below to aid in importing the data. You will

need to edit the file path accordingly.

fid = fopen('C:\Users\jschw\Dropbox\Class\OPTI 512 Linear Systems, Fourier

Transforms\Homeworks\phase.dat','rb');

phase = fread(fid, [1024 1024], 'double');

imshow(phase,[])

Plot the phase pattern ฮฆ(๐‘ฅ๐‘ฅ, ๐‘ฆ๐‘ฆ).

b) Create the complex array ๐‘“๐‘“(๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ) = ๐‘Ÿ๐‘Ÿ๐‘ฅ๐‘ฅ๐‘’๐‘’[โˆ’๐‘ ๐‘ ฮฆ(๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ)]. This will be the input to our

phase contrast system. Sensors and our eyes can only record the squared magnitude of

complex signals or |๐‘“๐‘“(๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ)|2. What is |๐‘“๐‘“(๐‘ฅ๐‘ฅ, ๐‘ฆ๐‘ฆ)|2 for this input?

|๐‘“๐‘“(๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ)|2 = ๐‘Ÿ๐‘Ÿ๐‘ฅ๐‘ฅ๐‘’๐‘’[โˆ’๐‘ ๐‘ ฮฆ(๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ)]๐‘Ÿ๐‘Ÿ๐‘ฅ๐‘ฅ๐‘’๐‘’[๐‘ ๐‘ ฮฆ(๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ)] = 1 everywhere, which means the object

is transparent.

c) The transfer function for this system is

๐ป๐ป(๐œ‰๐œ‰, ๐œ‚๐œ‚) = ๏ฟฝ๐‘Ÿ๐‘Ÿ๐‘ฅ๐‘ฅ๐‘’๐‘’ ๏ฟฝ๐‘ ๐‘ ๐œ‹๐œ‹2๏ฟฝ ๐‘“๐‘“๐‘๐‘๐‘Ÿ๐‘Ÿ ๐œ‰๐œ‰ = ๐œ‚๐œ‚ = 0

1 ๐‘๐‘๐‘ก๐‘กโ„Ž๐‘Ÿ๐‘Ÿ๐‘Ÿ๐‘Ÿ๐‘’๐‘’๐‘ ๐‘ ๐‘ ๐‘ ๐‘Ÿ๐‘Ÿ,

Page 7: Skeletons.jpg Ghost...mean value for the Ghost gray scale image is 212.062. c) Create an empty 1200 x 1200 pixel array and place the template ๐‘ก๐‘ก(๐‘ฅ๐‘ฅ, ๐‘ฆ๐‘ฆ) in the middle

so calculate ๐น๐น(๐œ‰๐œ‰, ๐œ‚๐œ‚) using the FFT routines in Matlab and then multiply ๐น๐น(0,0) by

๐‘Ÿ๐‘Ÿ๐‘ฅ๐‘ฅ๐‘’๐‘’ ๏ฟฝ๐‘ ๐‘  ๐œ‹๐œ‹2๏ฟฝ to create the output ๐บ๐บ(๐œ‰๐œ‰, ๐œ‚๐œ‚). Be careful with the shifting that occurs with the

FFT and also note that Matlab starts its arrays with a value of 1 instead of 0. Finally,

calculate output of the phase contrast system with the inverse FFT routines to get

๐‘”๐‘”(๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ). Plot |๐‘”๐‘”(๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ)|2.

The point here is that by simply multiplying the point ๐น๐น(0,0) by ๐‘Ÿ๐‘Ÿ๐‘ฅ๐‘ฅ๐‘’๐‘’ ๏ฟฝ๐‘ ๐‘  ๐œ‹๐œ‹2๏ฟฝ, we were

able to convert a pure phase input that is invisible to us since |๐‘“๐‘“(๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ)|2 is constant

into an output |๐‘”๐‘”(๐‘ฅ๐‘ฅ,๐‘ฆ๐‘ฆ)|2 that depicts the phase pattern.