Spatial Filtrering Lecture
Spatial Filtrering Lecture
Dr.
Irfan
Filters in Image Processing
□The name filter refers to modifying, or rejecting specified frequency components of an
image.
□For example, a filter that passes low frequencies is called a lowpass filter.
2
What is Frequency in Images?
□ Frequency is the rate of change.
□ High- Frequency images:
□ The intensity of an image changes a lot, and the
brightness level change quickly from one pixel to the
next.
□ Is relatively uniform in brightness or changes very Color changes gradually: Changes very rapidly
slowly A smooth, low- from one brightness to
frequency pattern. another: High-frequency
□
pattern.
Most of the images have both low and high-
frequency parts
3
Fundamentals of Spatial Filtering
4
Fundamentals of Spatial Filtering
The above is repeated for every pixel in the original image to generate the filtered
image
5
Spatial Filtering: Mathematical Form
6
Spatial Filtering Fundamentals
□There are two closely related concepts that must be
understood clearly when performing linear sequential
filtering
□Correlations: process of moving a filter mask over the image and
computing the sumof product at each location
7
Spatial Filtering Fundamentals
Correlatio
filter
n 244 510 738
244 255 246 1 2 3
1020 1200 1098
255 240 183 x 4 5 6 = = 8703
8
Spatial Filtering: Mask / Kernel / Convolution Matrix
□ In image processing, a kernel, convolution matrix or mask is a small
matrix
□ Itisuseful for blurring, sharpening, embossing, edge detection and
more
□ Thisisaccomplished by means of convolution between a kernel
and an image.
□ Important Features of kernel
□ Size: 3x3,5x5,9x9,21x21etc.
□ Shape: rectangle, strip, circular or user defined
□ Coefficients /Values: set based on the operations
□ Anchor point: mostly in the middle
12
Spatial Filtering Fundamentals: Convolution Matrix
□Convolution issimple mathematical
operation which is fundamental to
many common image processing
operators.
13
Smoothing Spatial Filtering
□ One of the simplest spatial filtering operations, we can perform is a
smoothing operation.
□ Smoothing (averaging) spatial filters are used to reduce sharp transitions in
intensity (random noise typically consists of sharp transitions in intensity), ex: noise
reduction/blurring.
11
Linear Noise Smoothing
□ The blurring (box, Gaussian) is a type of image-blurring filters that uses a
function for calculating the transformation to apply to each pixel in the
image.
□ Gaussian blur takes the weighted average around the pixel, while box-blur
just average all the pixels in the radius of the single pixel together.
12
Linear Noise Smoothing – Gaussian Filter
□ Using OpenCV
import cv2
img = cv2.imread("pyimg.jpg")
cv2.waitKey(0)
13