Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 -...

28

Transcript of Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 -...

Page 1: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.
Page 2: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

Lecture 03 Lecture 03 Area Based Image Processing Area Based Image Processing

Mata kuliah : T0283 - Computer VisionTahun : 2010

Page 3: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 3

Learning ObjectivesLearning Objectives

After carefullyAfter carefully listening this lecture, students will listening this lecture, students will be able to do the following :be able to do the following :

understand spatial information based image understand spatial information based image operation operation such as area-based processingsuch as area-based processing

demonstrate how area-based image processing demonstrate how area-based image processing is is performed (i.e. convolution-based image performed (i.e. convolution-based image processing)processing)

Page 4: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 4

What is a Mask ?What is a Mask ?

A mask is a small matrix whose values are called A mask is a small matrix whose values are called weightsweights

Each mask has an origin, which is usually one of its positionsEach mask has an origin, which is usually one of its positions

The origin of symmetric masks are usually their center pixel The origin of symmetric masks are usually their center pixel positionposition

For non-symmetric masks, any pixel location may be chosen For non-symmetric masks, any pixel location may be chosen as the origin (depending on the intended use)as the origin (depending on the intended use)

11 11 11 11 22 11 11

11 11 11 22 44 22 11

11 11 11 11 22 11 11

11

Page 5: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 5

Linear filtering is filtering in which the value of an Linear filtering is filtering in which the value of an output pixel is a linear combination of the values of output pixel is a linear combination of the values of the pixels in the input pixel's neighborhood.the pixels in the input pixel's neighborhood.

Linear filtering of an image is accomplished through Linear filtering of an image is accomplished through an operation called an operation called convolutionconvolution. .

Convolution is a neighborhood operation in which each Convolution is a neighborhood operation in which each output pixel is the weighted sum of neighboring input output pixel is the weighted sum of neighboring input pixels. The matrix of weights is called the convolution pixels. The matrix of weights is called the convolution kernel, also known as the filter.kernel, also known as the filter.

Applying Masks to Images : Linear Applying Masks to Images : Linear FilteringFiltering

Page 6: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 6

Applying Masks to Images : Linear Applying Masks to Images : Linear FilteringFiltering

Page 7: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 7

Rotate the convolution kernel 180 degrees about its Rotate the convolution kernel 180 degrees about its center element.center element.

Slide the center element of the convolution kernel so Slide the center element of the convolution kernel so that it lies on top of the (2,4) element of A.that it lies on top of the (2,4) element of A.

Multiply each weight in the rotated convolution kernel Multiply each weight in the rotated convolution kernel by the pixel of A underneath.by the pixel of A underneath.

Sum the individual products from step 3.Sum the individual products from step 3.

Hence the (2,4) output pixel is Hence the (2,4) output pixel is

1*2 + 8*9 + 15*4 + 7*7 + 14*5 + 16*3 + 13*6 1*2 + 8*9 + 15*4 + 7*7 + 14*5 + 16*3 + 13*6 + 20*1 + 22*8 = 575+ 20*1 + 22*8 = 575

Computing the (2,4) Output of Computing the (2,4) Output of ConvolutionConvolution

Page 8: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 8

Computing the (2,4) Output of Computing the (2,4) Output of ConvolutionConvolution

1717 2424 11 88 1515

2323 55 77 1414 1616

44 66 1313 2020 2222

1010 1212 1919 2121 33

1111 1818 2525 22 99

22 99 44

77 55 33

66 11 88

Image pixel Image pixel valuesvalues

Center of Center of KernelKernel

Values of rotated KernelValues of rotated Kernel

Page 9: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 9

Slide the center element of the correlation kernel so Slide the center element of the correlation kernel so that it lies on top of the (2,4) element of A.that it lies on top of the (2,4) element of A.

Multiply each weight in the rotated correlation kernel Multiply each weight in the rotated correlation kernel by the pixel of A underneath.by the pixel of A underneath.

Sum the individual products from step 2.Sum the individual products from step 2.

Hence the (2,4) output pixel is Hence the (2,4) output pixel is

1*8 + 8*1 + 15*6 + 7*3 + 14*5 + 16*7+ 13*4 1*8 + 8*1 + 15*6 + 7*3 + 14*5 + 16*7+ 13*4 + 20*9 + 22*2 = 585+ 20*9 + 22*2 = 585

Computing the (2,4) Output of Computing the (2,4) Output of CorrelationCorrelation

Page 10: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 10

1717 2424 11 88 1515

2323 55 77 1414 1616

44 66 1313 2020 2222

1010 1212 1919 2121 33

1111 1818 2525 22 99

88 11 66

33 55 77

44 99 22

Image pixel Image pixel valuesvalues

Center of Center of KernelKernel

Values of Correlation KernelValues of Correlation Kernel

Computing the (2,4) Output of Computing the (2,4) Output of CorrelationCorrelation

Page 11: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 11

Dealing with Image BordersDealing with Image Borders

Only convolve with interiorOnly convolve with interiorShrinks imageShrinks image

Zero-paddingZero-paddingResults in spurious gradientsResults in spurious gradients

Border replicationBorder replication

33

22

11

22

22

11

33

22

3322

2211

2222

3322

11-2-2-1-1

2244-1-1

111111

Page 12: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 12

Filtering Example Filtering Example How to treat image borders : Zero PaddingHow to treat image borders : Zero Padding

11 -1-1 -1-1

11 22 -1-1

11 11 11

22 22 22 33

22 11 33 33

22 22 11 22

11 33 22 22Rotate

11-1-1-1-1

1122-1-1

111111

Page 13: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 13

33

22

11

22

22

11

33

22

3322

2211

2222

3322 55

33

22

11

22

22

11

33

22

3322

2211

2222

3322

11-2-2-1-1

2244-1-1

111111

11-1-1-1-1

1122-1-1

111111

Step 1Step 1

Page 14: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 14

33

22

11

22

22

11

33

22

3322

2211

2222

3322 4455

33

22

11

22

22

11

33

22

3322

2211

2222

3322

33-1-1-2-2

2244-2-2

111111

11-1-1-1-1

1122-1-1

111111

Step 2Step 2

Page 15: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 15

33

22

11

22

22

11

33

22

3322

2211

2222

3322 44 4455

33

22

11

22

22

11

33

22

3322

2211

2222

3322

33-3-3-1-1

3344-2-2

111111

11-1-1-1-1

1122-1-1

111111

Step 3Step 3

Page 16: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 16

33

22

11

22

22

11

33

22

3322

2211

2222

3322 44 44 -2-255

33

22

11

22

22

11

33

22

3322

2211

2222

3322

11-3-3-3-3

1166-2-2

111111

11-1-1-1-1

1122-1-1

111111

Step 4Step 4

Page 17: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 17

33

22

11

22

22

11

33

22

3322

2211

2222

3322 44 44

99

-2-255

33

22

11

22

22

11

33

22

3322

2211

2222

3322

22-2-2-1-1

1144-1-1

222211

11-1-1-1-1

1122-1-1

111111

Step 5Step 5

Page 18: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 18

Final ResultFinal Result

22 22 22 33

22 11 33 33

22 22 11 22

11 33 22 22 1212

77

66

44

88

66

1414

44

5599

5599

551111

-2-255

I’I

Page 19: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 19

Smoothing (Low Pass Filtering)Smoothing (Low Pass Filtering)

Useful for noise reduction and image blurringUseful for noise reduction and image blurring

It removes the finer details of an imageIt removes the finer details of an image

Averaging or Mean (Box) FilterAveraging or Mean (Box) FilterThe elements of the mask must be positiveThe elements of the mask must be positive

The size of the mask determines the degree of smoothingThe size of the mask determines the degree of smoothing

111111

111111

111111

3 x 3 box filter kernel

Page 20: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 20

Gaussian Filter (LPF)Gaussian Filter (LPF)

The weights are sampled from a Gaussian function which The weights are sampled from a Gaussian function which fall off to zero at the mask’s edgesfall off to zero at the mask’s edges

0.003 0.013 0.022 0.013 0.0030.013 0.059 0.097 0.059 0.0130.022 0.097 0.159 0.097 0.0220.013 0.059 0.097 0.059 0.0130.003 0.013 0.022 0.013 0.003

5 x 5, = 1

Page 21: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 21

Gaussian Filter (cont’d)Gaussian Filter (cont’d)

Gaussian smoothing can be implemented efficiently, Gaussian smoothing can be implemented efficiently, thanks to the fact that the kernel is thanks to the fact that the kernel is separableseparable

Page 22: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 22

To convolve an image To convolve an image II with a n x n Gaussian mask with a n x n Gaussian mask GG with with = = GG

Build a 1-D Gaussian mask Build a 1-D Gaussian mask gg, of width n, with , of width n, with gg= = GG

Convolve each column of Convolve each column of II with with gg, yielding a ne image , yielding a ne image IIccConvolve each row of Convolve each row of IIcc with with gg

The value of The value of determines degree of smoothingdetermines degree of smoothing

Gaussian Filter (cont’d)Gaussian Filter (cont’d)

Page 23: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 23

Gaussian Filter (examples)Gaussian Filter (examples)

= 1 = 3

7 x 7 kernel

Original image Box filter

Page 24: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 24

Median Filter (non-linear)Median Filter (non-linear)

Effective for removing “salt & pepper” noise Effective for removing “salt & pepper” noise (random occurences of black & white pixels)(random occurences of black & white pixels)

Replace each pixel value by the median of the gray-Replace each pixel value by the median of the gray-levels in the neighborhood of the pixelslevels in the neighborhood of the pixels

10 20 20 15 99 20 20 25 2010 20 20 15 99 20 20 25 20

10 15 20 20 20 20 20 25 9910 15 20 20 20 20 20 25 99

sort

median

Page 25: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 25

Median Filter (non-linear)Median Filter (non-linear)

Page 26: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 26

Median Filter (non-linear)Median Filter (non-linear)

Page 27: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 27

Sharpening (High Pass Filtering)Sharpening (High Pass Filtering)

It is used to emphasize the fine details of an imageIt is used to emphasize the fine details of an image

Points of high contrast can be detected by computing Points of high contrast can be detected by computing intensity differences in local image regionsintensity differences in local image regions

The weights of the mask are both positive and negativeThe weights of the mask are both positive and negative

When the mask is over an area of constant or slowly When the mask is over an area of constant or slowly varying gray level, the result of convolution will be close to varying gray level, the result of convolution will be close to zerozero

When gray level is varying rapidly within the neighborhood, When gray level is varying rapidly within the neighborhood, the result of convolution will be a large numberthe result of convolution will be a large number

Typically, such points form the border between different Typically, such points form the border between different objects or scene parts (i.e., sharpening is a precursor step objects or scene parts (i.e., sharpening is a precursor step to edge detectionto edge detection

Page 28: Lecture 03 Area Based Image Processing Lecture 03 Area Based Image Processing Mata kuliah: T0283 - Computer Vision Tahun: 2010.

January 20, 2010 T0283 - Computer Vision 28

Sharpening (cont’d)Sharpening (cont’d)