0% found this document useful (0 votes)
3 views13 pages

Spatial Filtrering Lecture

The document discusses spatial filtering in image processing, focusing on the use of filters to modify or reject specific frequency components of an image. It explains the concepts of correlation and convolution, as well as the role of masks or kernels in applying these filters for tasks such as smoothing and edge detection. Additionally, it covers the mathematical foundation of spatial filtering and provides examples of linear noise smoothing techniques, particularly the Gaussian filter.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views13 pages

Spatial Filtrering Lecture

The document discusses spatial filtering in image processing, focusing on the use of filters to modify or reject specific frequency components of an image. It explains the concepts of correlation and convolution, as well as the role of masks or kernels in applying these filters for tasks such as smoothing and edge detection. Additionally, it covers the mathematical foundation of spatial filtering and provides examples of linear noise smoothing techniques, particularly the Gaussian filter.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Spatial Filtering (Linear Filtering)

• Filters in Image Processing


• Correlation & Convolution
• Linear Filters

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.

□Image processing filtersare mainly used to suppress either:

- The high frequencies in the image, i.e. smoothing the image

- The low frequencies i.e. enhancing/sharping or detecting edges in the image.

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.

□ Low Frequency images:

□ 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

□ Spatial filters contains two components


□Mask / Convolution Matrix / Kernel: A neighborhood of pixel (typically small rectangle)
□Filter Function: A predefined operations that isperformed on the image pixels with the
help of neighborhood.

□ Filtering creates a new pixel value with coordinates equal to the


coordinates of the center of the neighborhood, and whose values is the
result of filtering operations.

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

□Spatial Filtering of an image of size𝑴 × 𝑵 with a filter of


size 𝒎 ×
𝒏 is given by expression

□ Where 𝒘 is the mask and 𝒇 isthe image function

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

□Convolution: Same as correlation except the filterisfirstrotated by


180 degrees.

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

255 250 12 7 8 9 1785 2000 108

Convolutio Filter Rotated


n 244 255 246
180
9 8 7
2196 2040 1722

1530 1200 732


255 240 183 x 6 5 4 = = 10697
255 250 12 3 2 1 765 500 12

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.

□Thiscan be used in image processing


to implement operators whose output
pixel values are simple linear
combinations of certain input pixel
values.

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.

□ Types of smoothing filters:

□ Linear smoothing filters, ex:Gaussian filter

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")

blur_image = cv2.GaussianBlur(img, (7,7), 0)# (7,7): kernel


size- specifying height and width of Gaussian filter matrix,
must be odd numbers( 3*3, 5*5, 7*7), larger value create
more blurring, 0: sigma x(standard deviation in x direction)

cv2.imshow('Original Image', img) cv2.imshow('Blur Image',


blur_image)

cv2.waitKey(0)

13

You might also like