Top Banner
Matlab Tutorial Continued • Files, functions and images.
42
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Matlab Tutorial Continued Files, functions and images.

Matlab Tutorial Continued

• Files, functions and images.

Page 2: Matlab Tutorial Continued Files, functions and images.

Announcements

• Week of Feb. 17th Jacobs office hours change.– Tuesday, 18th 3-4.– Friday, 21st 3:30-4:30

• TA office hours still Monday 17th 4-6.

Page 3: Matlab Tutorial Continued Files, functions and images.

Files

Matlab

Page 4: Matlab Tutorial Continued Files, functions and images.

Functions

• Format: function o = test(x,y)

• Name function and file the same.

• Only first function in file is visible outside the file.

• Look at sample function

Page 5: Matlab Tutorial Continued Files, functions and images.

Images

• Black and white image is a 2D matrix.

• Intensities represented as pixels.

• Color images are 3D matrix, RBG.

• Matlab

Page 6: Matlab Tutorial Continued Files, functions and images.

Debugging

• Add print statements to function by leaving off ;

• keyboard

• debug and breakpoint

Page 7: Matlab Tutorial Continued Files, functions and images.

Conclusions

• Quick tour of matlab, you should teach yourself the rest. We’ll give hints in problem sets.

• Linear algebra allows geometric manipulation of points.

• Learn to love SVD.

Page 8: Matlab Tutorial Continued Files, functions and images.

Linear Filtering

• About modifying pixels based on neighborhood. Local methods simplest.

• Linear means linear combination of neighbors. Linear methods simplest.

• Useful to:– Integrate information over constant regions.– Scale.– Detect changes.

• Fourier analysis.• Many nice slides taken from Bill Freeman.

Page 9: Matlab Tutorial Continued Files, functions and images.

(Freeman)

Page 10: Matlab Tutorial Continued Files, functions and images.

(Freeman)

Page 11: Matlab Tutorial Continued Files, functions and images.

Convolution

• Convolution kernel g, represented as matrix.– it’s associative

• Result is:

Page 12: Matlab Tutorial Continued Files, functions and images.
Page 13: Matlab Tutorial Continued Files, functions and images.
Page 14: Matlab Tutorial Continued Files, functions and images.
Page 15: Matlab Tutorial Continued Files, functions and images.
Page 16: Matlab Tutorial Continued Files, functions and images.
Page 17: Matlab Tutorial Continued Files, functions and images.
Page 18: Matlab Tutorial Continued Files, functions and images.
Page 19: Matlab Tutorial Continued Files, functions and images.
Page 20: Matlab Tutorial Continued Files, functions and images.
Page 21: Matlab Tutorial Continued Files, functions and images.
Page 22: Matlab Tutorial Continued Files, functions and images.
Page 23: Matlab Tutorial Continued Files, functions and images.
Page 24: Matlab Tutorial Continued Files, functions and images.
Page 25: Matlab Tutorial Continued Files, functions and images.
Page 26: Matlab Tutorial Continued Files, functions and images.
Page 27: Matlab Tutorial Continued Files, functions and images.

Filtering to reduce noise

• Noise is what we’re not interested in.– We’ll discuss simple, low-level noise today:

Light fluctuations; Sensor noise; Quantization effects; Finite precision

– Not complex: shadows; extraneous objects.

• A pixel’s neighborhood contains information about its intensity.

• Averaging noise reduces its effect.

Page 28: Matlab Tutorial Continued Files, functions and images.

Additive noise

• I = S + N. Noise doesn’t depend on signal.

• We’ll consider:

ddistributey identicall ,

for t independen ,

tic.determinis

0)( with

ji

jiji

i

iiii

nn

nnnn

s

nEnsI

Page 29: Matlab Tutorial Continued Files, functions and images.

Average Filter• Mask with positive

entries, that sum 1.• Replaces each pixel

with an average of its neighborhood.

• If all weights are equal, it is called a BOX filter.

11

1111

11

11 111111

11

FF

1/91/9

(Camps)

Page 30: Matlab Tutorial Continued Files, functions and images.

Does it reduce noise?

• Intuitively, takes out small variations.

),0(~),(ˆ1)),(ˆ(

0)),(ˆ(

),(1

),(ˆm

1

),(),(ˆm

1 j)O(i,

)N(0,~j)N(i, with ),(),(ˆ),(

22

22

2/

2/

2/

2/

),(ˆ

2/

2/

2/

2/

2/

2/

2/

2/

mNjiN

mm

mjiNE

jiNE

kjhiNm

kjhiI

kjhiNkjhiI

jiNjiIjiI

m

mh

m

mk

jiN

m

mh

m

mk

m

mh

m

mk

(Camps)

2

2 2

Page 31: Matlab Tutorial Continued Files, functions and images.

Matlab Demo of Averaging

Page 32: Matlab Tutorial Continued Files, functions and images.

Example: Smoothing by Averaging

Page 33: Matlab Tutorial Continued Files, functions and images.

Smoothing as Inference About the Signal

+ =

Nearby points tell more about the signal than distant ones.

Neighborhood for averaging.

Page 34: Matlab Tutorial Continued Files, functions and images.

Gaussian Averaging

• Rotationally symmetric.

• Weights nearby pixels more than distant ones.– This makes sense

as probabalistic inference.

• A Gaussian gives a good model of a fuzzy blob

Page 35: Matlab Tutorial Continued Files, functions and images.

exp x2 y2

22

An Isotropic Gaussian

• The picture shows a smoothing kernel proportional to

(which is a reasonable model of a circularly symmetric fuzzy blob)

Page 36: Matlab Tutorial Continued Files, functions and images.

Smoothing with a Gaussian

Page 37: Matlab Tutorial Continued Files, functions and images.

The effects of smoothing Each row shows smoothingwith gaussians of differentwidth; each column showsdifferent realizations of an image of gaussian noise.

Page 38: Matlab Tutorial Continued Files, functions and images.

Efficient Implementation

• Both, the BOX filter and the Gaussian filter are separable:– First convolve each row with a 1D filter– Then convolve each column with a 1D

filter.

Page 39: Matlab Tutorial Continued Files, functions and images.

Smoothing as Inference About the Signal: Non-linear Filters.

+ =

What’s the best neighborhood for inference?

Page 40: Matlab Tutorial Continued Files, functions and images.

Filtering to reduce noise: Lessons

• Noise reduction is probabilistic inference.

• Depends on knowledge of signal and noise.

• In practice, simplicity and efficiency important.

Page 41: Matlab Tutorial Continued Files, functions and images.

Filtering and Signal

• Smoothing also smooths signal.• Matlab• Removes detail• Matlab• This is good and bad: - Bad: can’t remove noise w/out blurring

shape. - Good: captures large scale structure;

allows subsampling.

Page 42: Matlab Tutorial Continued Files, functions and images.

Subsampling

Matlab