86
DTU Compute Image Analysis Plenty of slides adapted from Thomas Moeslunds lectures Rasmus R. Paulsen Tim B. Dyrby DTU Compute [email protected] http://www.compute.dtu.dk/courses/02502

Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

Image Analysis

Plenty of slides adapted from Thomas Moeslunds lectures

Rasmus R. Paulsen

Tim B. Dyrby

DTU Compute

[email protected]

http://www.compute.dtu.dk/courses/02502

Page 2: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis2 DTU Compute, Technical University of Denmark

Lecture 4Neighbourhood Processing

Page 3: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis3 DTU Compute, Technical University of Denmark

What can you do after today? Describe the difference between point processing and neighbourhood

processing

Compute a rank filtered image using the min, max, median, and difference rank filters

Compute a mean filtered image

Decide if median or average filtering should be used for noise removal

Choose the appropriate image border handling based on a given input image

Implement and apply template matching

Compute the normalised cross correlation and explain why it should be used

Apply given image filter kernels to images

Use edge filters on images

Describe finite difference approximation of image gradients including the magnitude and the direction

Compute the magnitude of the gradient

Describe the concept of edge detection

Page 4: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis4 DTU Compute, Technical University of Denmark

Point processing

0 2

1 2

1 2 1

2 5 3

1 3

2 2

0 1

1 2 0

2 1 4

1 0 1

9

12

Input Output

• The value of the output pixel is only dependent on the value of one input pixel

• A global operation – changes all pixels

Page 5: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis5 DTU Compute, Technical University of Denmark

Point processing

Grey level enhancement

– Process one pixel at a time independent of all other pixels

– For example used to correct Brightness and Contrast

Too low

contrastCorrect

Too high

contrast

Too high

brightnessToo low

brightness

Page 6: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis6 DTU Compute, Technical University of Denmark

Neighbourhood processing

0 2

1 2

1 2 1

2 5 3

1 3

2 2

0 1

1 2 0

2 1 4

1 0 1

9

12

Input Output

• Several pixels in the input has an effect on the output

Page 7: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis7 DTU Compute, Technical University of Denmark

Use of filtering

Noise removal Enhance edges Smoothing

• Image processing

• Typically done before actual image analysis

Page 8: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis8 DTU Compute, Technical University of Denmark

Salt and pepper noise

Pixel values that are very different from their neighbours

Very bright or very dark spots

Scratches in X-rays

What is that?

Page 9: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis9 DTU Compute, Technical University of Denmark

Salt and pepper noise

Fake example

– Let us take a closer look at noise pixels

They are all 0 or 255

Should we just remove all the 0’s and 255’s from the image?

Page 10: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis10 DTU Compute, Technical University of Denmark

What is so special about noise?

What is the value of the pixel compared to the neighbours?

Average of the neighbours

– 170

Can we compare to the average?

– Difficult – should we remove all values bigger than average+1 ?

It is difficult to detect noise!

172, 169, 171, 168, 0, 169, 172, 173, 168

Page 11: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis11 DTU Compute, Technical University of Denmark

Noise – go away!

We can not tell what pixels are noise

One solution

– Set all pixels to the average of the neighbours (and the pixel itself)

Oh no!

– Problems!

– The noise “pollutes” the good pixels

172, 169, 171, 168, 0, 169, 172, 173, 168

170

169, 168, 0, 170, 172,173, 170, 172, 170

149

Page 12: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis12 DTU Compute, Technical University of Denmark

Page 13: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis13 DTU Compute, Technical University of Denmark

Page 14: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis14 DTU Compute, Technical University of Denmark

Page 15: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis15 DTU Compute, Technical University of Denmark

The median value

The values are sorted from low to high

The middle number is picked– The median value

169, 168, 0, 170,172, 173, 170, 172, 170

0,168, 169, 170, 170, 170,172, 172,173

Median

Noise has no influence on the median!

Page 16: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis16 DTU Compute, Technical University of Denmark

Noise away – the median filter

All pixels are set to the median of its neighbourhood (including the pixel itself)

Noise pixels do not pollute good pixels

172, 169, 171, 168, 0, 169, 172, 173, 168

170

169, 168, 0, 170, 172,173, 170, 172, 170

170

Page 17: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis17 DTU Compute, Technical University of Denmark

Noise removal – average filter

Scanned X-ray with salt and pepper noise

Average filter (3x3)

Page 18: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis18 DTU Compute, Technical University of Denmark

Noise removal – median filter

Scanned X-ray with salt and pepper noise

Median filter (3x3)

Page 19: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis19 DTU Compute, Technical University of Denmark

Image Filtering

Creates a new filtered image

Output pixel is computed based on a neighbourhood in the input image

3 x 3 neighbourhood– Filter size 3 x 3

– Kernel size 3 x 3

– Mask size 3 x 3

Larger filters often used– Size

7 x 7

– Number of elements

49

Page 20: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis20 DTU Compute, Technical University of Denmark

Page 21: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis21 DTU Compute, Technical University of Denmark

Page 22: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis22 DTU Compute, Technical University of Denmark

Page 23: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis23 DTU Compute, Technical University of Denmark

Rank filters

Based on sorting the pixel values in the neighbouring region

Minimum rank filter

– Darker image. Noise problems.

Maximum rank filter

– Lighter image. Noise problems.

Difference filter

– Enhances changes (edges)

0,168, 169, 170, 170, 170,172, 172,173

-

Page 24: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis24 DTU Compute, Technical University of Denmark

Page 25: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis25 DTU Compute, Technical University of Denmark

Page 26: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis26 DTU Compute, Technical University of Denmark

Page 27: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis27 DTU Compute, Technical University of Denmark

Correlation

What is it?

Two measurements

– Low correlation

– High correlation

High correlation means that there is a relation between the values

They look the same

Correlation is a measure of similarity

Low

High

Muscles

Math

Skills

Muscles

Bench P

ress

Page 28: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis28 DTU Compute, Technical University of Denmark

Why do we need similarity?

Image analysis is also about recognition of patterns

Often an example pattern is used

– Often with some kind of meta data to apply to the targets

We need something to tell us if there is a high match between our pattern and a part of the image

Example pattern

With meta information

Find matches

Page 29: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis29 DTU Compute, Technical University of Denmark

Correlation (1D)

1 1 2 2 1 1 2 2 1 1

1 2 1

4

5

4

1

1 * 1 + 2 * 1 + 1 * 2 = 5

Normalise!

Kernel

Signal (1D image)

4

1

Page 30: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis30 DTU Compute, Technical University of Denmark

Correlation (1D)

1 1 2 2 1 1 2 2 1 1

1 2 1

4

5

4

7

4

7

4

5

4

5

4

7

4

7

4

5

4

1

Page 31: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis31 DTU Compute, Technical University of Denmark

Normalisation

1 1 2 2 1 1 2 2 1 1

1 2 1

4

5

4

1

1 * 1 + 2 * 1 + 1 * 2 = 5

Normalise!4

1

• The sum of the kernel elements is used

• Keep the values in the same range as the input image

Sum is 4

Page 32: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis32 DTU Compute, Technical University of Denmark

Normalisation

Normalisation factor

– Sum of kernel coefficients

1 2 1h(x)

𝑥

ℎ 𝑥 = 1 + 2 + 1

Page 33: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis33 DTU Compute, Technical University of Denmark

Correlation on images

The filter is now 2D 1 1 1

1 1 1

1 1 1

0 2 4

1 2 2

1 6 3

1 2 1

2 5 3

2 1 3

1 3 1

2 2 2

0 1 3

1 2 0

2 1 4

1 0 1

9

12

9

1

Input OutputKernel

Kernel coefficients

Page 34: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis34 DTU Compute, Technical University of Denmark

Correlation on images

1 1 1

1 1 1

1 1 1

0 2 4

1 2 2

1 6 3

1 2 0

2 1 4

1 0 1

9

12

9

11

9

1

Input Output

1 3 1

2 2 2

0 1 3

1 2 1

2 5 3

2 1 3

Page 35: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis35 DTU Compute, Technical University of Denmark

Correlation on images

Input Output

The mask is moved row by row

No values at the border!

0 2 4

1 2 2

1 6 3

1 2 0

2 1 4

1 0 1

1 3 1

2 2 2

0 1 3

1 2 1

2 5 3

2 1 3

Page 36: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis38 DTU Compute, Technical University of Denmark

Page 37: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis39 DTU Compute, Technical University of Denmark

Page 38: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis40 DTU Compute, Technical University of Denmark

Page 39: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis41 DTU Compute, Technical University of Denmark

Page 40: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis42 DTU Compute, Technical University of Denmark

Page 41: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis43 DTU Compute, Technical University of Denmark

Page 42: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis44 DTU Compute, Technical University of Denmark

Mathematics of 2D Correlation

h

f

Correlation operator

1 2 1

1 3 1

1 2 1

0 2 4

1 2 2

1 6 3

1 2 1

2 5 3

2 1 3

1 3 1

2 2 2

0 1 3

1 2 0

2 1 4

1 0 1

𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 ∘ ℎ(𝑥, 𝑦)

Page 43: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis45 DTU Compute, Technical University of Denmark

Mathematics of 2D Correlation

1 2 1

1 3 1

1 2 1

0 2 4

1 2 2

1 6 3

1 2 1

2 5 3

2 1 3

1 3 1

2 2 2

0 1 3

1 2 0

2 1 4

1 0 1

h

fh(0,0)

f(2,1)

Example g(2,1)

i = -1, j = -1

i = 1, j = 0

𝑔 𝑥, 𝑦 =

𝑗=−𝑅

𝑅

𝑖=−𝑅

𝑅

ℎ(𝑖, 𝑗) ∙ 𝑓(𝑥 + 𝑖, 𝑦 + 𝑗)

Page 44: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis46 DTU Compute, Technical University of Denmark

Mathematics of 2D Correlation

1 2 1

1 3 1

1 2 1

0 2 4

1 2 2

1 6 3

1 2 1

2 5 3

2 1 3

1 3 1

2 2 2

0 1 3

1 2 0

2 1 4

1 0 1

h

f

𝑔 𝑥, 𝑦 =

𝑗=−𝑅

𝑅

𝑖=−𝑅

𝑅

ℎ(𝑖, 𝑗) ∙ 𝑓(𝑥 + 𝑖, 𝑦 + 𝑗)

𝑔(𝑥, 𝑦) = 1 ∙ 2 + 2 ∙ 0 + 1 ∙ 1 + 1 ∙ 1 + 3 ∙ 4 + 1 ∙ 2 + 1 ∙ 0 + 2 ∙ 1 + 1 ∙ 0

Page 45: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis47 DTU Compute, Technical University of Denmark

𝑔 𝑥, 𝑦 =

𝑗=−𝑅

𝑅

𝑖=−𝑅

𝑅

ℎ(𝑖, 𝑗) ∙ 𝑓(𝑥 + 𝑖, 𝑦 + 𝑗)

𝑔 2,2 =ℎ −1,−1 ⋅ 𝑓 1,1 + ℎ 0,−1 ⋅ 𝑓 2,1 + ℎ 1,−1 ⋅ 𝑓 3,1 +ℎ −1,0 ⋅ 𝑓 1,2 + ℎ 0,0 ⋅ 𝑓 2,2 + ℎ 1,0 ⋅ 𝑓 3,2 +ℎ −1,1 ⋅ 𝑓 1,3 + ℎ 0,1 ⋅ 𝑓 2,3 + ℎ 1,1 ⋅ 𝑓 3,3

Page 46: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis48 DTU Compute, Technical University of Denmark

2D Kernel Normalisation

1 2 1

1 3 1

1 2 1

h

Normalisation factor:

1+ 2+ 1+ 1+ 3+ 1+ 1+ 2+ 1 = 13

𝑥

𝑦

ℎ(𝑥, 𝑦)

Page 47: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis49 DTU Compute, Technical University of Denmark

Page 48: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis50 DTU Compute, Technical University of Denmark

Page 49: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis51 DTU Compute, Technical University of Denmark

Page 50: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis52 DTU Compute, Technical University of Denmark

Smoothing filters

Also know as – Smoothing kernel, Mean filter, Low pass filter, blurring

The simplest filter: – Spatial low pass filter

– Removes high frequencies

Another mask: – Gaussian filter

1 1 1

1 1 1

1 1 1

9

1

1 2 1

2 4 2

1 2 116

1

Why Gaussian?

Page 51: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis53 DTU Compute, Technical University of Denmark

Use of smoothing

3x3 7x7 11x11 15x15

Page 52: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis54 DTU Compute, Technical University of Denmark

Use of smoothing

Large kernels smooth more

Removes high frequency information

Good at enhancing big structures

3x3 15x15

Page 53: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis55 DTU Compute, Technical University of Denmark

Page 54: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis56 DTU Compute, Technical University of Denmark

Page 55: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis57 DTU Compute, Technical University of Denmark

Page 56: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis58 DTU Compute, Technical University of Denmark

Border handling

0 2 4

1 2 2

1 6 3

1 2 1

2 5 3

2 1 3

1 3 1

2 2 2

0 1 3

1 2 0

2 1 4

1 0 1

Input Output

No values at the border!

Page 57: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis59 DTU Compute, Technical University of Denmark

Border handling – extend the input

0 2 4

1 2 2

1 6 3

1 2 1

2 5 3

2 1 3

1 3 1

2 2 2

0 1 3

1 2 0

2 1 4

1 0 1

Input

0 0 0 0 00

0

0

0

0

• Zero padding – what happens?

• Zero is black – creates dark border around the image

Page 58: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis60 DTU Compute, Technical University of Denmark

Page 59: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis61 DTU Compute, Technical University of Denmark

Page 60: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis62 DTU Compute, Technical University of Denmark

Page 61: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis63 DTU Compute, Technical University of Denmark

Border handling – extend the input

0 2 4

1 2 2

1 6 3

1 2 1

2 5 3

2 1 3

1 3 1

2 2 2

0 1 3

1 2 0

2 1 4

1 0 1

Input

1 2 0 1 31

1

2

1

1

• Reflection

• Normally better than zero padding

Page 62: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis64 DTU Compute, Technical University of Denmark

What is the connection to deep learning?

https://se.mathworks.com/videos/introduction-to-deep-learning-what-are-convolutional-neural-networks--1489512765771.html

Page 63: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis65 DTU Compute, Technical University of Denmark

Banks of filters

The part of the network that touches the image consists of a bank of filters

– Organised in a multi-level hierarchy

The weights of the filters are adapted to the problem

Page 64: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis66 DTU Compute, Technical University of Denmark

Template Matching

Template

– Skabelon på dansk

Locates objects in images

Input

Template

Output: Correlation image

Page 65: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis67 DTU Compute, Technical University of Denmark

Template Matching

The correlation between the template and the input image is computed for each pixel

Input

Template

Output: Correlation image

Page 66: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis68 DTU Compute, Technical University of Denmark

Template Matching

The pixel with the highest value is found in the output image

– Here is the highest correlation

Input

Template

Output: Correlation image

Page 67: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis69 DTU Compute, Technical University of Denmark

Template Matching

This corresponds to the found pattern in the input image

Input

Template

Output: Correlation image

Page 68: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis70 DTU Compute, Technical University of Denmark

Problematic Correlation

Correlation matching has problem with light areas –why?

Input (f)

Template (h)

Output: Correlation imageFake max

Real max

Very High!𝑔 𝑥, 𝑦 =

𝑗=−𝑅

𝑅

𝑖=−𝑅

𝑅

ℎ(𝑖, 𝑗) ∙ 𝑓(𝑥 + 𝑖, 𝑦 + 𝑗)

Page 69: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis71 DTU Compute, Technical University of Denmark

Normalised Cross Correlation

Input (f)

Template (h)

Output: Correlation image

Real max

NCC x, y =Correlation

Length of image patch ⋅ Length of template

Page 70: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis72 DTU Compute, Technical University of Denmark

Length of template

Vector length

– Put all pixel values into a vector

– Compute the length of this vector

Describes the intensity of the template

– Bright template has a large length

– Dark template has a small length

Template (h)

Length of template =

𝑗=−𝑅

𝑅

𝑖=−𝑅

𝑅

ℎ(𝑖, 𝑗) ∙ ℎ(𝑖, 𝑗)

Page 71: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis73 DTU Compute, Technical University of Denmark

Length of image patch

Vector length based on pixel values in image patch

Describes the intensity of the image patch

Template (h)

Input (f) with patch

Page 72: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis74 DTU Compute, Technical University of Denmark

Normalised Cross Correlation

The length of the image patch and the length of template normalise the NCC

If the image is very bright the NCC will be “pulled down”

NCC x, y =Correlation

Length of image patch ⋅ Length of template

Page 73: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis75 DTU Compute, Technical University of Denmark

Normalised Cross Correlation

NCC will be between

– 0 : No similarity between template and image patch

– 1 : Template and image patch are identical

Input (f)

Template (h)

Output: Correlation image

Real max

NCC x, y =Correlation

Length of image patch ⋅ Length of template

Page 74: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis76 DTU Compute, Technical University of Denmark

Page 75: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis77 DTU Compute, Technical University of Denmark

Page 76: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis78 DTU Compute, Technical University of Denmark

Page 77: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis79 DTU Compute, Technical University of Denmark

Edges

An edge is where there is a high change in gray level values

Objects are often separated from the background by edgesGray level profile

Page 78: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis80 DTU Compute, Technical University of Denmark

Edges

The profile as a function f(d)

What value is high when there is an edge?

– The slope of f

– The slope of the tangent at d

f (d)

𝑓′(𝑑)

Page 79: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis81 DTU Compute, Technical University of Denmark

Finite Difference

Definition of slope

Approximation

Simpler approximation

h = 1

𝑓′ 𝑑 = limℎ→0

𝑓 𝑑 + ℎ − 𝑓(𝑑)

𝑓′ 𝑑 ≈𝑓 𝑑 + ℎ − 𝑓(𝑑)

𝑓′ 𝑑 ≈ 𝑓 𝑑 + 1 − 𝑓(𝑑)

Page 80: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis82 DTU Compute, Technical University of Denmark

Edges

Discrete approximation of f’(d)

Can be implemented as a filter

-1 0 1

f(d-2) f(d-1) f(d) f(d+1) f(d+2) f(d+3)

f (d)

𝑓′ 𝑑 ≈ 𝑓 𝑑 + 1 − 𝑓(𝑑)

Page 81: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis83 DTU Compute, Technical University of Denmark

Edges in 2D

Changes in gray level values

– Image gradient

– Gradient is the 2D derivative of a 2D function f(x,y)

– Equal to the slope of the image

– A steep slope is equal to an edge

𝛻𝑓 𝑥, 𝑦 = Ԧ𝐺(𝑔𝑥, 𝑔𝑦)

Page 82: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis84 DTU Compute, Technical University of Denmark

2D Gradient

magnitude = 𝑔𝑥2 + 𝑔𝑦

2

Page 83: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis85 DTU Compute, Technical University of Denmark

Edge filter kernel

The Prewitt filter is a typical edge filter

Output image has high values where there are edges

-1 0 1

-1 0 1

-1 0 1

Vertical Prewitt filter

Page 84: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis86 DTU Compute, Technical University of Denmark

Prewitt filter

Original Prewitt Prewitt

Hot colormap

Smooth 15x15

Smooth 15x15

Prewitt

Page 85: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis87 DTU Compute, Technical University of Denmark

Edge detection

Edge filter

– Prewitt for example

Thresholding

– Separate edges from non-edges

Output is binary image

– Edges are white

Page 86: Image Analysis - week4... · 2021. 2. 28. · DTU Compute 11 DTU Compute, Technical University of Denmark Image Analysis 2021 Noise –go away! We can not tell what pixels are noise

DTU Compute

2021Image Analysis88 DTU Compute, Technical University of Denmark

Exercise data