Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

3.4 Fundamentals of Spatial Filtering: Filter

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

3.

4 Fundamentals of Spatial Filtering

• Filter, Mask, Kernel,


Template, Window

• Coef cients

• Linear Filtering vs
Nonlinear Filtering
(e.g., median ltering)
fi

fi

3.4 Fundamentals of Spatial Filtering


• Filter, Mask, Kernel,
Template, Window

• Coef cients

• Linear Filtering vs
Nonlinear Filtering
(e.g., median ltering)
fi

fi

3.4 Fundamentals of Spatial Filtering


- Linear Spatial Filtering
a b
g ( x, y ) = å å w(s, t ) f ( x + s, y + t )
s = - at = - b

• The center coef cient of the kernel, w(0, 0), aligns


with the pixel at location (x, y).

• For a kernel of size m x n, we assume that m = 2a +


1 and n = 2b + 1, where a and b are nonnegative
integers.
fi

3.4 Fundamentals of Spatial Filtering


- Linear Spatial Filtering
One of the simplest spatial filtering for smoothing
operation - Averaging Filter

Box Filter Weighted Average


3.4 Fundamentals of Spatial Filtering
- Linear Spatial Filtering
One of the simplest spatial filtering for smoothing
operation - Averaging Filter

• original image of size


500*500 pixels
• ltering with an averaging
lter of increasing sizes
– 3, 5, 9, 15 and 35

Zero padding for edges


fi
fi



3.4 Fundamentals of Spatial Filtering
- Spatial Filtering at the Edges
At the edges of an image we are missing pixels to
form a neighbourhood

credit of this slide: C. Nikou


3.4 Fundamentals of Spatial Filtering
- Spatial Filtering at the Edges
Zero Padding

Replicate Padding

Mirror Padding

credit of this slide: C. Nikou


3.4 Fundamentals of Spatial Filtering
- Spatial Filtering at the Edges

Zero Padding Mirror Padding Replicate Padding

more applicable when


useful when the areas
the areas near the
near the border of the
border contain image
image are constant
details
3.4 Fundamentals of Spatial Filtering
- Spatial Correlation and Convolution
• The ltering we have been talking about so far is
referred to as correlation with the lter itself referred to
as the correlation kernel

• The mechanics of spatial convolution are the same,


except that the correlation kernel is rotated by 180°.

• For symmetric lters it makes no difference.

credit of this slide: C. Nikou


fi
fi
fi
3.4 Fundamentals of Spatial Filtering
- Spatial Correlation and Convolution
Correlation

Convolution
3.4 Fundamentals of Spatial Filtering
- Spatial Correlation and Convolution

discrete unit impulse


- A function that contains a
single 1 with the rest being 0’s

discrete impulse of
strength (amplitude) A
3.4 Fundamentals of Spatial Filtering
- Spatial Correlation and Convolution

Correlation Convolution
rotated version exactly copy
of the kernel at of the kernel at
the location of the location of
the impulse the impulse
3.4 Fundamentals of Spatial Filtering
- Spatial Correlation and Convolution

δ(x − 2, y − 2)

Correlation Convolution
rotated version exactly copy
of the kernel at of the kernel at
the location of the location of
the impulse the impulse
3.4 Fundamentals of Spatial Filtering
- Spatial Correlation and Convolution
Correlation Convolution
rotated version exactly copy
of the kernel at of the kernel at
the location of the location of
the impulse the impulse

That’s why convolution is more widely used.


- When talking about ltering and kernels, you are likely to encounter the terms convolution
lter, convolution mask, or convolution kernel to denote lter kernels.
- In this book, when we use the term linear spatial ltering, we mean convolving a kernel with
an image. Not to imply necessarily that the kernel is used for convolution.
fi
fi

fi
fi

3.4 Fundamentals of Spatial Filtering


- Separable Filter Kernels

m x n kernel 1 x n vector
m x 1 vector

Image size M x N (including padding)

Directly calculate: O(MNmn)


If separable kernel: O(MN(m+n)) (MNm + MNn)

3.5 Smoothing (Lowpass) Spatial Filters


- Box Filter Kernels

3x3

11x11 21x21

Box Filter Weighted Average


3.5 Smoothing (Lowpass) Spatial Filters
- Box Filter Kernels

Box Filter Weighted Average

• Limitation of box lters:


- poor choices in many applications, ex. defocused
lens
- box lters favor blurring along perpendicular
directions

fi
fi

3.5 Smoothing (Lowpass) Spatial Filters


- Box Filter Kernels

Box kernel Gaussian kernel


71x71 151x151,
with K = 1, σ = 25

hard transitions at the signi cantly smoother


onset and end of the results around the edge
ramp transitions
fi

You might also like