EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday!...

37
Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on campus. Class is therefore cancelled on Tuesday. Please work on your presentations instead!

Transcript of EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday!...

Page 1: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Midterm is on Thursday!

Project presentations are May 17th, 22nd and 24th

Next week there is a strike on campus. Class is therefore cancelled on Tuesday.

Please work on your presentations instead!

Page 2: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

REVIEW

From results on practice midterm: Half of the class needs another

review!

Page 3: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Spatial frequency

Page 4: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

1D Frequency Spectrum

Page 5: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Frequency spectrum

1 2 3 4 5 6

Page 6: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on
Page 7: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

2D Fourier Transform Power Spectrum

• 2D Fourier transform of the Dunes photograph

Page 8: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Sampling

• Both in space and time

• Select acquisition speed

• Select sensor size / Optical magnification

• Aliasing

Page 9: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Nyquist sampling = twice the frequency

Page 10: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Aliasing

Page 11: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Aliasing

• (Image downsized around four times)

Page 12: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Histogram shows distribution of gray-levels in an image

Page 13: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Lets plot the histogram of this synthetic image

4

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

7

Histogram Processing:

Graylevel

9

15

7

5 Histogram:

• Distribution of gray-levels can be judged by measuring a Histogram

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

8

For B-bit image,

• Initialize 2B counters with 0 • Loop over all pixels x,y • When encountering gray level f(x,y)=i, increment the counter number i

• With proper normalization, the histogram can be interpreted as an estimate of the probability density function (pdf) of the underlying random variable (the graylevel) •You can also use fewer, larger bins to trade off amplitude

Histogram Processing:

Page 14: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

4

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

7

Histogram Processing:

Graylevel

9

15

7

5 Histogram:

• Distribution of gray-levels can be judged by measuring a Histogram

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

8

For B-bit image,

• Initialize 2B counters with 0 • Loop over all pixels x,y • When encountering gray level f(x,y)=i, increment the counter number i

• With proper normalization, the histogram can be interpreted as an estimate of the probability density function (pdf) of the underlying random variable (the graylevel) •You can also use fewer, larger bins to trade off amplitude

Histogram Processing:

Page 15: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Grayscale Histogram

5

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

9

Example:

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

10

Example:

Page 16: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Color Histogram

Page 17: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Image enhancement

• In the pixel domain, for example:

1

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

1

Image Enhancement I: Point-wise Operations

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

2

• Make image “better” for a specific application – The idea of “better” is somewhat subjective

• We distinguish two domains:

– Spatial or Pixel domain: – Frequency Domain:

• For this section: Pixel Domain

– Operations on single pixel at a time – Operations on groups of pixels (neighborhoods)

),(or ),( nmfyxf),(or ),( vuFwwF yx

Pixel 4-Neighbors 8-Neighbors

Image Enhancement: Operating on the Pixels

Page 18: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Convolution

4

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

Defining convolution

¦ �� lk

lkglnkmfnmgf,

],[],[],)[(

f

• Let f be the image and g be the kernel. The output of convolving f with g is denoted f * g.

Source: F. Durand

• Convention: kernel is “flipped” • MATLAB: conv2 vs. filter2 (also imfilter)

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

Key properties

• Linearity: filter(f1 + f2 ) = filter(f1) + filter(f2)

• Shift invariance: same behavior regardless of pixel location: filter(shift(f)) = shift(filter(f))

• Theoretical result: any linear shift-invariant operator can be represented as a convolution

Page 19: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Convolution properties

4

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

Defining convolution

¦ �� lk

lkglnkmfnmgf,

],[],[],)[(

f

• Let f be the image and g be the kernel. The output of convolving f with g is denoted f * g.

Source: F. Durand

• Convention: kernel is “flipped” • MATLAB: conv2 vs. filter2 (also imfilter)

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

Key properties

• Linearity: filter(f1 + f2 ) = filter(f1) + filter(f2)

• Shift invariance: same behavior regardless of pixel location: filter(shift(f)) = shift(filter(f))

• Theoretical result: any linear shift-invariant operator can be represented as a convolution

Page 20: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

“Drag-and-Stamp”

2

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

3

Overview of Spatial Filtering • Local linear oprations on an image

)1,1()1,1(),1()1,1(),(

98

21

���������� yxfwyxfwyxfwyxfwyxg

Input: f(x,y), Output: g(x,y)

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

• We replace each pixel with a weighted average of its neighborhood

• The weights are called the filter kernel • What are the weights for the average of a

3x3 neighborhood?

Moving average

1 1 1

1 1 1

1 1 1

“box filter” Source: D. Lowe

Page 21: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

What to do at the edges of the image

5

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

Important details • What is the size of the output? • MATLAB: filter2(g, f, shape)

– shape = ‘full’: output size is sum of sizes of f and g – shape = ‘same’: output size is same as f – shape = ‘valid’: output size is difference of sizes of f

and g

f

g g

g g

f

g g

g g

f

g g

g g

full same valid

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

10

Image Enhancement:Spatial Filtering Operation • An important point: Edge Effects

– To compute all pixel values in the output image, we need to fill in a “border”

Mask dimension = 2M+1

Border dimension = M

Page 22: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

6

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

11

Image Enhancement:Spatial Filtering Operation • An important point: Edge Effects (Ex.: 5x5 Mask)

– How to fill in a “border” • Zeros (Ringing) • Replication (Better) • Reflection (“Best”) a b

c d

a b

a b c d

a

a

c

c

b

b

d

d

• Procedure: – Replicate row-wise – Replicate column-wise – Apply filtering – Remove borders

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

Implementation

• What about near the edge? – the filter window falls off the edge of the

image – need to extrapolate – methods (MATLAB):

• clip filter (black): imfilter(f, g, 0) • wrap around: imfilter(f, g, ‘circular’) • copy edge: imfilter(f, g, ‘replicate’) • reflect across edge: imfilter(f, g, ‘symmetric’)

Source: S. Marschner

Page 23: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

MATLAB methods:

6

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

11

Image Enhancement:Spatial Filtering Operation • An important point: Edge Effects (Ex.: 5x5 Mask)

– How to fill in a “border” • Zeros (Ringing) • Replication (Better) • Reflection (“Best”) a b

c d

a b

a b c d

a

a

c

c

b

b

d

d

• Procedure: – Replicate row-wise – Replicate column-wise – Apply filtering – Remove borders

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

Implementation

• What about near the edge? – the filter window falls off the edge of the

image – need to extrapolate – methods (MATLAB):

• clip filter (black): imfilter(f, g, 0) • wrap around: imfilter(f, g, ‘circular’) • copy edge: imfilter(f, g, ‘replicate’) • reflect across edge: imfilter(f, g, ‘symmetric’)

Source: S. Marschner

Page 24: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

What happens:

• Filter kernel operations on matrix (image)

• “Drag and Stamp” operation

• Using MATLAB: filter2(A,B)

• use: ’same’, ‘valid’ and ‘full’ parameters (ex: filter2(A,B,’full’)

Page 25: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Filtering example

• MATLAB code how to apply filter kernel:

Page 26: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Gaussian blur filtering

• Filter with Gaussian kernel

• Filtering twice with a certain Gaussian is the same as filtering with this Gaussian convolved with itself -> MORE BLUR

Page 27: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

13

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

Gaussian Kernel

• Constant factor at front makes volume sum to 1 (can be ignored, as we should re-normalize weights to sum to 1 in any case)

0.003 0.013 0.022 0.013 0.003 0.013 0.059 0.097 0.059 0.013 0.022 0.097 0.159 0.097 0.022 0.013 0.059 0.097 0.059 0.013 0.003 0.013 0.022 0.013 0.003

5 x 5, V = 1

Source: C. Rasmussen

fspecial(‘gauss’,5,1)

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

Choosing kernel width

• Gaussian filters have infinite support, but discrete filters use finite kernels

Source: K. Grauman

Page 28: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

13

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

Gaussian Kernel

• Constant factor at front makes volume sum to 1 (can be ignored, as we should re-normalize weights to sum to 1 in any case)

0.003 0.013 0.022 0.013 0.003 0.013 0.059 0.097 0.059 0.013 0.022 0.097 0.159 0.097 0.022 0.013 0.059 0.097 0.059 0.013 0.003 0.013 0.022 0.013 0.003

5 x 5, V = 1

Source: C. Rasmussen

fspecial(‘gauss’,5,1)

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

Choosing kernel width

• Gaussian filters have infinite support, but discrete filters use finite kernels

Source: K. Grauman

Page 29: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Example code MATLAB

ImageO = imread('MushroomDownload.jpg'); Image = ImageO(:,:,1);

H = fspecial('motion',20,45); MotionBlur = imfilter(Image,H,'replicate');

subplot(2,1,2), imagesc(MotionBlur),axis equal, axis off, colormap gray

subplot(2,1,1), imagesc(Image),axis equal, axis off, colormap gray

Page 30: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Blurring can be used for denoising

1

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

1

Image Enhancement II: Neighborhood Operations

EE 264: Image Processing and Reconstruction Peyman Milanfar UCSC EE Dept.

2

Image Enhancement:Spatial Filtering Operation • Idea: Use a “mask” to alter pixel values

according to local operation • Aim: (De)-Emphasize some spatial frequencies

in the image.

• (Example from course textbook Gonzales & Wood)

Page 31: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Try this out on noisy data with median, gaussian etc…

Page 32: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Note: it’s better to vectorize your code in MATLAB

tic for t = 1:1024 y(t) = sin(2*pi*t/512); end toc

tic y = sin(pi*(0:(1/256):2)); toc

You can read up on this at:http://www.mathworks.com/help/matlab/matlab_prog/vectorization.html

Page 33: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Fourier Transform

• Examples of spatial filtering in frequency space

Page 34: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Some Fourier Transform Pairs

4 October 2016 671999-2016 by Richard Alan Peters II

Table: Richard Szeliski, Computer Vision and Applications, Springer, 2010, ISBN 978-1-84882-935-0, p.137, http://szeliski.org/Book/.

Page 35: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Fourier Transform Pairs

4 October 2016 681999-2016 by Richard Alan Peters II

Page 36: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on

Lets do an experiment with spatial frequency imaging

• Take an image of the line pairs with your cell phone

• If you don't have one, come up here and take them with a camera

• Download to your computer and Fourier transform the data. Can you recognize the spatial frequencies from the image?

Page 37: EE264, Spring 18, Section 01 - Midterm is on Thursday! · 2019. 9. 13. · Midterm is on Thursday! Project presentations are May 17th, 22nd and 24th Next week there is a strike on