43
Linear Filtering – Part I Selim Aksoy Department of Computer Engineering Department of Computer Engineering Bilkent University [email protected]

Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Linear Filtering – Part I

Selim Aksoy

Department of Computer EngineeringDepartment of Computer Engineering

Bilkent University

[email protected]

Page 2: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Importance of neighborhood

� Both zebras and dalmatians have black and white pixels in

CS 484, Spring 2011 ©2011, Selim Aksoy 2

� Both zebras and dalmatians have black and white pixels in similar numbers.

� The difference between the two is the characteristic appearance of small group of pixels rather than individual pixel values.

Adapted from Pinar Duygulu, Bilkent University

Page 3: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Outline

� We will discuss neighborhood operations that work with the values of the image pixels in the neighborhood.neighborhood.

� Spatial domain filtering

� Frequency domain filtering

� Image enhancement

CS 484, Spring 2011 ©2011, Selim Aksoy 3

� Image enhancement

� Finding patterns

Page 4: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Spatial domain filtering

� What is the value of the center pixel?

3 3 3

3 ? 33

� What assumptions are you making to infer the center

3 ? 3

3 3 3

3 4 3

2 ? 3

3

3

CS 484, Spring 2011 ©2011, Selim Aksoy 4

making to infer the center value?

2 ? 3

3 4 2

3

Page 5: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Spatial domain filtering

� Some neighborhood operations work with

� the values of the image pixels in the neighborhood, and

� the corresponding values of a subimage that has the same dimensions as the neighborhood.

� The subimage is called a filter (or mask, kernel, template, window).

� The values in a filter subimage are referred to as coefficients, rather than pixels.

CS 484, Spring 2011 ©2011, Selim Aksoy 5

coefficients, rather than pixels.

Page 6: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Spatial domain filtering

� Operation: modify the pixels in an image based on some function of the pixels in their neighborhood.

� Simplest: linear filtering (replace each pixel by a linear combination of its neighbors).

� Linear spatial filtering is often referred to as “convolving an image with a filter”.

CS 484, Spring 2011 ©2011, Selim Aksoy 6

Page 7: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Linear filtering

∑ −−=⊗=lk

lkglnkmhgInmf,

],[],[],[

g [m]2Linear system: Input: 2 2 2 2

g [m]h [m]

0 1 2

-1-1

∑ −==k

kgkhmf ][][]0[

Output?

h [-k] f [m=0]=-2

0 1 2 3

1 1 10 0

0 1 2

2

-1 -1

CS 484, Spring 2011 ©2011, Selim Aksoy 7

h [1-k]

0 1 2

2

-1 -1

∑ −==k

kgkhmf ][]1[]1[ f [m=1]=-4

∑ −==k

kgkhmf ][]2[]2[ f [m=2]=0

Page 8: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Linear filtering

g [m,n] f [m,n]

For a linear spatially invariant system

∑ −−=⊗=lk

lkglnkmhgInmf,

],[],[],[

-1 2 -1

111 115 113 111 112 111 112 111

135 138 137 139 145 146 149 147

163 168 188 196 206 202 206 207

m=0 1 2 …? ? ? ? ? ? ? ?

? -5 9 -9 21 -12 10 ?

? -29 18 24 4 -7 5 ?

CS 484, Spring 2011 ©2011, Selim Aksoy 8

⊗-1 2 -1

-1 2 -1

-1 2 -1

g[m,n] h[m,n]f[m,n]

=180 184 206 219 202 200 195 193

189 193 214 216 104 79 83 77

191 201 217 220 103 59 60 68

195 205 216 222 113 68 69 83

199 203 223 228 108 68 71 77

? -50 40 142 -88 -34 10 ?

? -41 41 264 -175 -71 0 ?

? -24 37 349 -224 -120 -10 ?

? -23 33 360 -217 -134 -23 ?

? ? ? ? ? ? ? ?

Page 9: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Linear filtering

� Filtering process:

� Masks operate on a neighborhood of pixels.

� The filter mask is centered on a pixel.

� The mask coefficients are multiplied by the pixel values in its neighborhood and the products are summed.

The result goes into the corresponding pixel position in

CS 484, Spring 2011 ©2011, Selim Aksoy 9

� The result goes into the corresponding pixel position in the output image.

� This process is repeated by moving the filter mask from pixel to pixel in the image.

Page 10: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Linear filtering

� This is called the cross-correlation operation and is denoted by

F[r,c]

Mask overlaid withimage at [r,c]

G[r,c]

H[-1,-1] H[-1,0] H[-1,1]

H[0,-1] H[0,0] H[0,1]

H[1,-1] H[1,0] H[1,1]

CS 484, Spring 2011 ©2011, Selim Aksoy 10

Input image Output image

H[1,-1] H[1,0] H[1,1]

Filter

Page 11: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Linear filtering

� Be careful about indices, image borders and padding during implementation.

CS 484, Spring 2011 ©2011, Selim Aksoy 11

Border padding examples.

Page 12: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Smoothing spatial filters

� Often, an image is composed of

� some underlying ideal structure, which we want to detect and describe,detect and describe,

� together with some random noise or artifact, which we would like to remove.

� Smoothing filters are used for blurring and for noise reduction.

Linear smoothing filters are also called averaging

CS 484, Spring 2011 ©2011, Selim Aksoy 12

� Linear smoothing filters are also called averaging filters.

Page 13: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Smoothing spatial filters

CS 484, Spring 2011 ©2011, Selim Aksoy 13

Averaging (mean) filter Weighted average

Page 14: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Smoothing spatial filters

1010 1111 1010

99 1010 1111 11

00 00

1100

11 XX XX XX

XX 1010

XX XX

XX

XX

1010 99 1010

1010

1010

22

99

00

99

99

99

99

99

11

9999

1010

1010 1111

1111

1111

1111

1111

10101010

II

11

11

11

11 11

11

FF

XX

XX

XX

XX

XX

XX

XX

XX

XX

XX

XX

XXXX

1/91/9

OO

CS 484, Spring 2011 ©2011, Selim Aksoy 14

1/9.(10x1 + 11x1 + 10x1 + 9x1 + 10x1 + 11x1 + 10x1 + 9x1 + 10x1) = 1/9.(10x1 + 11x1 + 10x1 + 9x1 + 10x1 + 11x1 + 10x1 + 9x1 + 10x1) = 1/9.( 90) = 101/9.( 90) = 10

1111

11 11

11

111/91/9

Adapted from Octavia Camps, Penn State

Page 15: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Smoothing spatial filters

XX XX XX

XX

XX XX

XX

XX1010 1111 1010

99 1010 1111 11

00 00

1100

11

II

11

11

11

11 11

11

FF

XX

2020

XX

XX

XX

XX

XX

XX

XX

XX

XX

XX

XXXX

1/91/9

OO1010 99 1010

1010

1010

22

99

00

99

99

99

99

99

11

9999

1010

1010 1111

1111

1111

1111

1111

10101010

CS 484, Spring 2011 ©2011, Selim Aksoy 15

1/9.(10x1 + 9x1 + 11x1 + 9x1 + 99x1 + 11x1 + 11x1 + 10x1 + 10x1) = 1/9.(10x1 + 9x1 + 11x1 + 9x1 + 99x1 + 11x1 + 11x1 + 10x1 + 10x1) = 1/9.( 180) = 201/9.( 180) = 20

1111

11 11

11

111/91/9

Adapted from Octavia Camps, Penn State

Page 16: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Smoothing spatial filters

� Common types of noise:

� Salt-and-pepper noise: contains random contains random occurrences of black and white pixels.

� Impulse noise: contains random occurrences of white pixels.

Original Salt and pepper noise

CS 484, Spring 2011 ©2011, Selim Aksoy 16

� Gaussian noise: variations in intensity drawn from a Gaussian normal distribution.

Gaussian noiseImpulse noiseAdapted from Linda Shapiro, U of Washington

Page 17: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Gaussiannoise

Salt and peppernoise

3x3

5x5

CS 484, Spring 2011 ©2011, Selim Aksoy 17

7x7Adapted from Linda Shapiro,U of Washington

Page 18: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Smoothing spatial filters

CS 484, Spring 2011 ©2011, Selim Aksoy 18

Adapted from Gonzales and Woods

Page 19: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Smoothing spatial filters

CS 484, Spring 2011 ©2011, Selim Aksoy 19

Adapted from Gonzales and Woods

Page 20: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Smoothing spatial filters

CS 484, Spring 2011 ©2011, Selim Aksoy 20

Adapted from Darrell and Freeman, MIT

Page 21: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Smoothing spatial filters

A weighted average that weighs pixels at its center much more strongly than its boundaries.

CS 484, Spring 2011 ©2011, Selim Aksoy 21

its boundaries.

2D Gaussian filter

Adapted from Martial Hebert, CMU

Page 22: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Smoothing spatial filters

� If σ is small: smoothing will have little effect.

� If σ is larger: neighboring pixels will have larger weights resulting in consensus of the neighbors.

CS 484, Spring 2011 ©2011, Selim Aksoy 22

� If σ is very large: details will disappear along with the noise.

Adapted from Martial Hebert, CMU

Page 23: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Smoothing spatial filters

Result of blurring using a uniform local model.

Result of blurring using a

CS 484, Spring 2011 ©2011, Selim Aksoy 23

Produces a set of narrow horizontal and vertical bars –ringing effect.

blurring using a Gaussian filter.

Adapted from David Forsyth, UC Berkeley

Page 24: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Smoothing spatial filters

CS 484, Spring 2011 ©2011, Selim Aksoy 24

Adapted from Martial Hebert, CMU

Page 25: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Smoothing spatial filters

CS 484, Spring 2011 ©2011, Selim Aksoy 25Adapted from Martial Hebert, CMU

Page 26: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Order-statistic filters

� Order-statistic filters are nonlinear spatial filters whose response is based on

� ordering (ranking) the pixels contained in the image area encompassed by the filter, and then

� replacing the value of the center pixel with the value determined by the ranking result.

� The best-known example is the median filter.

It is particularly effective in the presence of

CS 484, Spring 2011 ©2011, Selim Aksoy 26

� It is particularly effective in the presence of impulse or salt-and-pepper noise, with considerably less blurring than linear smoothing filters.

Page 27: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Order-statistic filters

1010 1111 1010

99 1010 1111 11

00 00

1100

11 XX XX XX

XX 1010

XX XX

XX

XX

1010 99 1010

1010

1010

22

99

00

99

99

99

99

99

11

9999

1010

1010 1111

1111

1111

1111

1111

10101010

II

XX

XX

XX

XX

XX

XX

XX

XX

XX

XX

XX

XXXX

OO

CS 484, Spring 2011 ©2011, Selim Aksoy 27

10,11,10,9,10,11,10,9,1010,11,10,9,10,11,10,9,10 9,9,10,10,10,10,10,11,119,9,10,10,10,10,10,11,11sortsort

medianmedian

Adapted from Octavia Camps, Penn State

Page 28: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Order-statistic filters

1010 1111 1010

99 1010 1111 11

00 00

1100

11 XX XX XX

XX

XX XX

XX

XX

1010 99 1010

1010

1010

22

99

00

99

99

99

99

99

11

9999

1010

1010 1111

1111

1111

1111

1111

10101010

II

XX

1010

XX

XX

XX

XX

XX

XX

XX

XX

XX

XX

XXXX

OO

CS 484, Spring 2011 ©2011, Selim Aksoy 28

10,9,11,9,99,11,11,10,1010,9,11,9,99,11,11,10,10 9,9,10,10,10,11,11,11,999,9,10,10,10,11,11,11,99sortsort

medianmedian

Adapted from Octavia Camps, Penn State

Page 29: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

3x3

Mean Gaussian Median

Salt-and-pepper noise

5x5

CS 484, Spring 2011 ©2011, Selim Aksoy 29

7x7

Adapted from Linda Shapiro,U of Washington

Page 30: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

3x3

Mean Gaussian Median

Gaussian noise

5x5

CS 484, Spring 2011 ©2011, Selim Aksoy 30

7x7Adapted from Linda Shapiro,U of Washington

Page 31: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Order-statistic filters

CS 484, Spring 2011 ©2011, Selim Aksoy 31

Adapted from Gonzales and Woods

Page 32: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Order-statistic filters

CS 484, Spring 2011 ©2011, Selim Aksoy 32Adapted from Martial Hebert, CMU

Page 33: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Sharpening spatial filters

� Objective of sharpening is to highlight or enhance fine detail in an image.

� Since smoothing (averaging) is analogous to integration, sharpening can be accomplished by spatial differentiation.

� First-order derivative of 1D function f(x)f(x+1) – f(x).

CS 484, Spring 2011 ©2011, Selim Aksoy 33

� Second-order derivative of 1D function f(x)f(x+1) – 2f(x) + f(x-1).

Page 34: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Sharpening spatial filters

CS 484, Spring 2011 ©2011, Selim Aksoy 34Adapted from Gonzales and Woods

Page 35: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Sharpening spatial filters

CS 484, Spring 2011 ©2011, Selim Aksoy 35Adapted from Gonzales and Woods

Page 36: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Sharpening spatial filters

� Observations:

� First-order derivatives generally produce thicker edges in an image.in an image.

� Second-order derivatives have a stronger response to fine detail (such as thin lines or isolated points).

� First-order derivatives generally have a stronger response to a gray level step.

� Second-order derivatives produce a double response at

CS 484, Spring 2011 ©2011, Selim Aksoy 36

� Second-order derivatives produce a double response at step changes in gray level.

Page 37: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Sharpening spatial filters

CS 484, Spring 2011 ©2011, Selim Aksoy 37

Page 38: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Sharpening spatial filters

CS 484, Spring 2011 ©2011, Selim Aksoy 38

Adapted from Gonzales and Woods

Page 39: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Sharpening spatial filters

Robert’s cross-gradient operators

CS 484, Spring 2011 ©2011, Selim Aksoy 39

Sobel gradient operators

Page 40: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Sharpening spatial filters

CS 484, Spring 2011 ©2011, Selim Aksoy 40

High-boost filtering

Adapted from Darrell and Freeman, MIT

Page 41: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Sharpening spatial filters

CS 484, Spring 2011 ©2011, Selim Aksoy 41

Adapted from Darrell and Freeman, MIT

Page 42: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Sharpening spatial filters

CS 484, Spring 2011 ©2011, Selim Aksoy 42

Adapted from Darrell and Freeman, MIT

Page 43: Linear Filtering –Part I - Bilkent Universitysaksoy/courses/cs484-Spring... · Sharpening spatial filters Objective of sharpening is to highlight or enhance fine detail in an image

Combining spatial enhancement methods

CS 484, Spring 2011 ©2011, Selim Aksoy 43