SlideShare a Scribd company logo
1 of 57
Spatial Filtering
CS474/674 - Prof. Bebis
Sections 3.4, 3.5, 3.6, 3.7, 3.8
Spatial Filtering Methods
output image
Spatial Filtering (cont’d)
• Spatial filters are defined by:
(1) Neighborhood (i.e., which pixels to process)
(2) Operation (i.e., how to process the pixels in the specified
neighborhood)
output image
Spatial Filtering – Neighborhood
• Usually, it has a square shape K x K (we call it a “window”).
– e.g., 3x3 or 5x5
center
Spatial filtering - Operation
output image
• A new value is obtained by processing the pixels in the window.
• Stored at the corresponding center location of the window
in the output image.
z’5 = 5z1 -3z2+z3-z4-2z5-3z6+z8-z9-9z7
Example:
Linear vs Non-Linear filters
• Depending on the operator used, a filter can be linear
or non-linear
output image
z’5 = 5z1 -3z2+z3-z4-2z5-3z6+z8-z9-9z7
Examples:
z’5 = max(z1,z2,z3,z4,z5,z6,z7,z8,z9)
linear
non-linear
Linear Operators
• Two common linear operators are:
– Correlation
– Convolution
• The output is a linear combination of the inputs.
Correlation (linear operator)
output image
• The output of correlation is a weighted sum of the input pixels.
The weights are defined by
a K x K mask (has the same
size as the window):
Correlation (cont’d)
Output
Image
w(i,j)
f(i,j)
/2 /2
/2 /2
( , ) ( , ) ( , ) ( , ) ( , )
K K
s K t K
g i j w i j f i j w s t f i s j t
 
    
 
g(i,j)
The output image is
generated by moving the
center of the mask at
each location of the input
image.
i,j=0,1,…,N-1
Handling Locations Close to Boundaries
Usually, we pad with zeroes
Alternatively, skip the first/last few rows/columns
0 0 0 ……………………….0
0
0
0
……………………….0
Correlation (cont’d)
Often used in applications where
we need to measure the similarity
between an image and a pattern
(e.g., template matching).
Simple template matching
does not work in most
practical cases.
Convolution (linear operator)
• Similar to correlation except that the mask is first flipped
both horizontally and vertically.
• Note: if w(i, j) is symmetric (i.e., w(i, j)=w(-i,-j)), then
convolution is equivalent to correlation!
/2 /2
/2 /2
( , ) ( , ) ( , ) ( , ) ( , )
K K
s K t K
g i j w i j f i j w s t f i s j t
 
    
 
i,j=0,1,…,N-1
Example
Correlation:
Convolution:
Filter Categories
• We will focus on two types of filters:
– Smoothing (also called “low-pass”) filters
• Remove details
– Sharpening (also called “high-pass”) filters
• Enhance details
Smoothing Filters (low-pass)
• Useful for reducing noise and removing small details.
– The elements of the mask must be positive.
– Mask elements sum to 1 assuming normalized weights (i.e.,
divide each weight by the sum of weights).
Smoothing filters – Example
smoothed image
input image
Sharpening Filters (high-pass)
• Useful for emphasizing fine details but can enhance noise.
– The elements of the mask contain both positive and negative
weights.
– Mask elements sum to 0.
Sharpening Filters - Example
• e.g., emphasize edges in an image
Sharpening Filters - Example
sharpened image
input image
Note: for better visualization, the
original image is typically added to
the sharpened image.
Common Smoothing Filters
• Averaging (linear)
• Gaussian (linear)
• Median filtering (non-linear)
Smoothing Filters: Averaging
The mask weights are all equal to 1
Smoothing Filters: Averaging (cont’d)
• Mask size determines degree of smoothing (i.e., loss of detail).
3x3 5x5 7x7
15x15 25x25
original
Smoothing Filters: Averaging (cont’d)
15 x 15 averaging After image thresholding
Example: extract largest, brightest objects
Smoothing filters: Gaussian
• The mask weights are the sampled values of a 2D Gaussian:
Smoothing filters: Gaussian (cont’d)
• Mask size depends on σ, e.g., it is usually chosen as
follows:
Smoothing filters: Gaussian (cont’d)
• In this case, σ controls the amount of smoothing
(since mask size depends on it)
σ = 3
σ = 1.4
Smoothing filters: Gaussian (cont’d)
Example
Averaging vs Gaussian Smoothing
Averaging
Gaussian
Smoothing Filters: Median Filtering
(non-linear)
• Very effective for removing “salt and pepper” noise (i.e.,
random occurrences of black and white pixels).
averaging
median
filtering
Smoothing Filters: Median Filtering (cont’d)
• Idea: replace each pixel by the median in a neighborhood
around the pixel.
• The size of the neighborhood controls the amount of
smoothing.
Sharpening Filters
• Common sharpening filters
– Unsharp masking
– High Boost filtering
– Gradient (1st derivative)
– Laplacian (2nd derivative)
Sharpening Filters: Unsharp Masking &
High Boost Filtering
• First, obtain a sharp image by subtracting a smoothed
image (i.e., low-passed (LP)) from the original image:
- =
Note: contrast enhancement
has been applied for
better visualization
( , ) ( , ) ( , )
mask LP
g x y f x y f x y
 
( , )
mask
g x y
( , )
LP
f x y
( , )
f x y
Sharpening Filters: Unsharp Masking &
High Boost Filtering (cont’d)
• Image sharpening emphasizes edges but other details are lost.
– Add a weighted portion of gmask back to the original image.
– When k=1, this process is known as high unsharp masking.
– When k>1, this process is known as high boost filtering.
+ k =
( , ) ( , ) ( , ), 0
mask
g x y f x y kg x y k
  
( , )
f x y ( , )
mask
g x y ( , )
g x y
High Boost Filtering - Example
original
Gaussian
smoothed
gmask
Unsharp
Masking
(k=1)
Highboost
Filtering
(k>1)
2D Example:
Sharpening Filters: Derivatives
• The derivative of an image results in a sharpened image.
• Image derivatives can be computed using the gradient:
Gradient
• The gradient is a vector which has magnitude and direction:
Gradient (cont’d)
• Gradient magnitude: provides information about edge
strength.
• Gradient direction: perpendicular to the direction of the
edge (useful for tracing object boundaries).
Gradient Computation
• Approximate partial derivatives using finite differences:
Δx
232 177 82 7
241 18 152 140
156 221 67 3
100 45 1 103
 
 
 
 
 
 
x
y
Notation:
Gradient Computation (cont’d)
sensitive to vertical edges
sensitive to horizontal edges
y2=y3+Dy, y3=y, x3=x, Dy=1
Example: visualize partial derivatives
f
x


f
y


• Image derivatives can be visualized as an image
by mapping the values to [0, 255]
Implement Gradient Using Masks
• We can implement and using masks:
(x+1/2,y)
(x,y+1/2)
*
*
good approximation
at (x+1/2,y)
good approximation
at (x,y+1/2)
Derivatives are not
computed at the same
location!
Implement Gradient Using Masks (cont’d)
• A different approximation of the gradient:
• We can implement and using the following masks:
*
(x+1/2,y+1/2)
good approximation
Derivatives are
computed at the
same location!
Implement Gradient Using Masks (cont’d)
• Other approximations
Sobel
Prewitt
Example: Visualize Gradient Magnitude
f
y


f
x


Gradient Magnitude
(isotropic, i.e., detects
edges in all directions)
• The gradient magnitude can be visualized
as an image by mapping the values to [0, 255]
Second Derivative – 1D case
( ) ( 1) ( )
( ) ( 1) ( ) ( 1) ( 1) 2 ( )
f x f x f x
f x f x f x f x f x f x
   
  
       
Second Derivative – 1D case (cont’d)
• Often, points that lie on an edge
can be detected by:
(1) Local maxima or
minima of the first derivative.
(2) Zero-crossings
of the second derivative (i.e., where
the second derivative changes sign). 2nd derivative
1st derivative
Second Derivative – 1D case (cont’d)
Example:
Second Derivative – 2D case: Laplacian
The Laplacian is defined as:
(dot product)
Approximate
2nd partial
derivatives:
Second Derivative – 2D case: Laplacian
(cont’d)
Laplacian Mask
Edges can
be found
by detecting
the zero-
crossings
input image output image
5
5
5
5 5
-5 -5
-10
-10
-10
10
Second Derivative – 2D case: Laplacian
(cont’d)
• Other realizations of the Laplacian mask found in practice.
Visualize the results of the Laplacian
• Add the results of the Laplacian to the original
image for better visualization
2
2
2
( , ) ( , ) ( , )
where,
( , ) is input image,
( , ) is sharpenend images,
-1 if ( , ) has a negative center value
and 1 if ( , ) has a positive center value.
g x y f x y c f x y
f x y
g x y
c f x y
c f x y
 
  
 
 
 
Visualize the results of the Laplacian
(cont’d)
no normalization,
negative values
clipped to zero
blurred image
scaled to [0, 255]
Example:
Laplacian vs Gradient
Laplacian Sobel
• Laplacian localizes edges better (zero-crossings).
• Higher order derivatives are typically more sensitive to noise.
• Laplacian is less computational expensive (i.e., one mask).
• Laplacian can provide edge magnitude information
but no information about edge direction.
Example
Example
Example
Quiz #2
• When: October 2, 2023
• What: Arithmetic, Logical and Geometric Transformations,
Spatial Transformations

More Related Content

Similar to Spatial Filtering in intro image processingr

03 cie552 image_filtering_spatial
03 cie552 image_filtering_spatial03 cie552 image_filtering_spatial
03 cie552 image_filtering_spatialElsayed Hemayed
 
Chapter10 image segmentation
Chapter10 image segmentationChapter10 image segmentation
Chapter10 image segmentationasodariyabhavesh
 
Module-5-1_230523_171754 (1).pdf
Module-5-1_230523_171754 (1).pdfModule-5-1_230523_171754 (1).pdf
Module-5-1_230523_171754 (1).pdfvikasmittal92
 
image segmentation by ppres.pptx
image segmentation by ppres.pptximage segmentation by ppres.pptx
image segmentation by ppres.pptxmohan134666
 
CSE367 Lecture- image sinal processing lecture
CSE367 Lecture- image sinal processing lectureCSE367 Lecture- image sinal processing lecture
CSE367 Lecture- image sinal processing lectureFatmaNewagy1
 
Image enhancement
Image enhancementImage enhancement
Image enhancementAyaelshiwi
 
05_Spatial_Filtering.ppt
05_Spatial_Filtering.ppt05_Spatial_Filtering.ppt
05_Spatial_Filtering.pptpawankamal3
 
Spatial Filters (Digital Image Processing)
Spatial Filters (Digital Image Processing)Spatial Filters (Digital Image Processing)
Spatial Filters (Digital Image Processing)Kalyan Acharjya
 
ImageSegmentation (1).ppt
ImageSegmentation (1).pptImageSegmentation (1).ppt
ImageSegmentation (1).pptNoorUlHaq47
 
ImageSegmentation.ppt
ImageSegmentation.pptImageSegmentation.ppt
ImageSegmentation.pptAVUDAI1
 
ImageSegmentation.ppt
ImageSegmentation.pptImageSegmentation.ppt
ImageSegmentation.pptDEEPUKUMARR
 
3 intensity transformations and spatial filtering slides
3 intensity transformations and spatial filtering slides3 intensity transformations and spatial filtering slides
3 intensity transformations and spatial filtering slidesBHAGYAPRASADBUGGE
 
COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...
COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...
COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...Hemantha Kulathilake
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1aravindangc
 

Similar to Spatial Filtering in intro image processingr (20)

03 cie552 image_filtering_spatial
03 cie552 image_filtering_spatial03 cie552 image_filtering_spatial
03 cie552 image_filtering_spatial
 
Chapter10 image segmentation
Chapter10 image segmentationChapter10 image segmentation
Chapter10 image segmentation
 
Module-5-1_230523_171754 (1).pdf
Module-5-1_230523_171754 (1).pdfModule-5-1_230523_171754 (1).pdf
Module-5-1_230523_171754 (1).pdf
 
image segmentation by ppres.pptx
image segmentation by ppres.pptximage segmentation by ppres.pptx
image segmentation by ppres.pptx
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
CSE367 Lecture- image sinal processing lecture
CSE367 Lecture- image sinal processing lectureCSE367 Lecture- image sinal processing lecture
CSE367 Lecture- image sinal processing lecture
 
Image enhancement
Image enhancementImage enhancement
Image enhancement
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
 
05_Spatial_Filtering.ppt
05_Spatial_Filtering.ppt05_Spatial_Filtering.ppt
05_Spatial_Filtering.ppt
 
Spatial Filters (Digital Image Processing)
Spatial Filters (Digital Image Processing)Spatial Filters (Digital Image Processing)
Spatial Filters (Digital Image Processing)
 
ImageSegmentation (1).ppt
ImageSegmentation (1).pptImageSegmentation (1).ppt
ImageSegmentation (1).ppt
 
ImageSegmentation.ppt
ImageSegmentation.pptImageSegmentation.ppt
ImageSegmentation.ppt
 
ImageSegmentation.ppt
ImageSegmentation.pptImageSegmentation.ppt
ImageSegmentation.ppt
 
Image segmentation
Image segmentationImage segmentation
Image segmentation
 
SPATIAL FILTER
SPATIAL FILTERSPATIAL FILTER
SPATIAL FILTER
 
Spatial filtering
Spatial filteringSpatial filtering
Spatial filtering
 
Spatial domain and filtering
Spatial domain and filteringSpatial domain and filtering
Spatial domain and filtering
 
3 intensity transformations and spatial filtering slides
3 intensity transformations and spatial filtering slides3 intensity transformations and spatial filtering slides
3 intensity transformations and spatial filtering slides
 
COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...
COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...
COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filterin...
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1
 

Recently uploaded

result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 

Recently uploaded (20)

result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 

Spatial Filtering in intro image processingr

  • 1. Spatial Filtering CS474/674 - Prof. Bebis Sections 3.4, 3.5, 3.6, 3.7, 3.8
  • 3. Spatial Filtering (cont’d) • Spatial filters are defined by: (1) Neighborhood (i.e., which pixels to process) (2) Operation (i.e., how to process the pixels in the specified neighborhood) output image
  • 4. Spatial Filtering – Neighborhood • Usually, it has a square shape K x K (we call it a “window”). – e.g., 3x3 or 5x5 center
  • 5. Spatial filtering - Operation output image • A new value is obtained by processing the pixels in the window. • Stored at the corresponding center location of the window in the output image. z’5 = 5z1 -3z2+z3-z4-2z5-3z6+z8-z9-9z7 Example:
  • 6. Linear vs Non-Linear filters • Depending on the operator used, a filter can be linear or non-linear output image z’5 = 5z1 -3z2+z3-z4-2z5-3z6+z8-z9-9z7 Examples: z’5 = max(z1,z2,z3,z4,z5,z6,z7,z8,z9) linear non-linear
  • 7. Linear Operators • Two common linear operators are: – Correlation – Convolution • The output is a linear combination of the inputs.
  • 8. Correlation (linear operator) output image • The output of correlation is a weighted sum of the input pixels. The weights are defined by a K x K mask (has the same size as the window):
  • 9. Correlation (cont’d) Output Image w(i,j) f(i,j) /2 /2 /2 /2 ( , ) ( , ) ( , ) ( , ) ( , ) K K s K t K g i j w i j f i j w s t f i s j t          g(i,j) The output image is generated by moving the center of the mask at each location of the input image. i,j=0,1,…,N-1
  • 10. Handling Locations Close to Boundaries Usually, we pad with zeroes Alternatively, skip the first/last few rows/columns 0 0 0 ……………………….0 0 0 0 ……………………….0
  • 11. Correlation (cont’d) Often used in applications where we need to measure the similarity between an image and a pattern (e.g., template matching). Simple template matching does not work in most practical cases.
  • 12. Convolution (linear operator) • Similar to correlation except that the mask is first flipped both horizontally and vertically. • Note: if w(i, j) is symmetric (i.e., w(i, j)=w(-i,-j)), then convolution is equivalent to correlation! /2 /2 /2 /2 ( , ) ( , ) ( , ) ( , ) ( , ) K K s K t K g i j w i j f i j w s t f i s j t          i,j=0,1,…,N-1
  • 14. Filter Categories • We will focus on two types of filters: – Smoothing (also called “low-pass”) filters • Remove details – Sharpening (also called “high-pass”) filters • Enhance details
  • 15. Smoothing Filters (low-pass) • Useful for reducing noise and removing small details. – The elements of the mask must be positive. – Mask elements sum to 1 assuming normalized weights (i.e., divide each weight by the sum of weights).
  • 16. Smoothing filters – Example smoothed image input image
  • 17. Sharpening Filters (high-pass) • Useful for emphasizing fine details but can enhance noise. – The elements of the mask contain both positive and negative weights. – Mask elements sum to 0.
  • 18. Sharpening Filters - Example • e.g., emphasize edges in an image
  • 19. Sharpening Filters - Example sharpened image input image Note: for better visualization, the original image is typically added to the sharpened image.
  • 20. Common Smoothing Filters • Averaging (linear) • Gaussian (linear) • Median filtering (non-linear)
  • 21. Smoothing Filters: Averaging The mask weights are all equal to 1
  • 22. Smoothing Filters: Averaging (cont’d) • Mask size determines degree of smoothing (i.e., loss of detail). 3x3 5x5 7x7 15x15 25x25 original
  • 23. Smoothing Filters: Averaging (cont’d) 15 x 15 averaging After image thresholding Example: extract largest, brightest objects
  • 24. Smoothing filters: Gaussian • The mask weights are the sampled values of a 2D Gaussian:
  • 25. Smoothing filters: Gaussian (cont’d) • Mask size depends on σ, e.g., it is usually chosen as follows:
  • 26. Smoothing filters: Gaussian (cont’d) • In this case, σ controls the amount of smoothing (since mask size depends on it) σ = 3 σ = 1.4
  • 27. Smoothing filters: Gaussian (cont’d) Example
  • 28. Averaging vs Gaussian Smoothing Averaging Gaussian
  • 29. Smoothing Filters: Median Filtering (non-linear) • Very effective for removing “salt and pepper” noise (i.e., random occurrences of black and white pixels). averaging median filtering
  • 30. Smoothing Filters: Median Filtering (cont’d) • Idea: replace each pixel by the median in a neighborhood around the pixel. • The size of the neighborhood controls the amount of smoothing.
  • 31. Sharpening Filters • Common sharpening filters – Unsharp masking – High Boost filtering – Gradient (1st derivative) – Laplacian (2nd derivative)
  • 32. Sharpening Filters: Unsharp Masking & High Boost Filtering • First, obtain a sharp image by subtracting a smoothed image (i.e., low-passed (LP)) from the original image: - = Note: contrast enhancement has been applied for better visualization ( , ) ( , ) ( , ) mask LP g x y f x y f x y   ( , ) mask g x y ( , ) LP f x y ( , ) f x y
  • 33. Sharpening Filters: Unsharp Masking & High Boost Filtering (cont’d) • Image sharpening emphasizes edges but other details are lost. – Add a weighted portion of gmask back to the original image. – When k=1, this process is known as high unsharp masking. – When k>1, this process is known as high boost filtering. + k = ( , ) ( , ) ( , ), 0 mask g x y f x y kg x y k    ( , ) f x y ( , ) mask g x y ( , ) g x y
  • 34. High Boost Filtering - Example original Gaussian smoothed gmask Unsharp Masking (k=1) Highboost Filtering (k>1) 2D Example:
  • 35. Sharpening Filters: Derivatives • The derivative of an image results in a sharpened image. • Image derivatives can be computed using the gradient:
  • 36. Gradient • The gradient is a vector which has magnitude and direction:
  • 37. Gradient (cont’d) • Gradient magnitude: provides information about edge strength. • Gradient direction: perpendicular to the direction of the edge (useful for tracing object boundaries).
  • 38. Gradient Computation • Approximate partial derivatives using finite differences: Δx 232 177 82 7 241 18 152 140 156 221 67 3 100 45 1 103             x y Notation:
  • 39. Gradient Computation (cont’d) sensitive to vertical edges sensitive to horizontal edges y2=y3+Dy, y3=y, x3=x, Dy=1
  • 40. Example: visualize partial derivatives f x   f y   • Image derivatives can be visualized as an image by mapping the values to [0, 255]
  • 41. Implement Gradient Using Masks • We can implement and using masks: (x+1/2,y) (x,y+1/2) * * good approximation at (x+1/2,y) good approximation at (x,y+1/2) Derivatives are not computed at the same location!
  • 42. Implement Gradient Using Masks (cont’d) • A different approximation of the gradient: • We can implement and using the following masks: * (x+1/2,y+1/2) good approximation Derivatives are computed at the same location!
  • 43. Implement Gradient Using Masks (cont’d) • Other approximations Sobel Prewitt
  • 44. Example: Visualize Gradient Magnitude f y   f x   Gradient Magnitude (isotropic, i.e., detects edges in all directions) • The gradient magnitude can be visualized as an image by mapping the values to [0, 255]
  • 45. Second Derivative – 1D case ( ) ( 1) ( ) ( ) ( 1) ( ) ( 1) ( 1) 2 ( ) f x f x f x f x f x f x f x f x f x               
  • 46. Second Derivative – 1D case (cont’d) • Often, points that lie on an edge can be detected by: (1) Local maxima or minima of the first derivative. (2) Zero-crossings of the second derivative (i.e., where the second derivative changes sign). 2nd derivative 1st derivative
  • 47. Second Derivative – 1D case (cont’d) Example:
  • 48. Second Derivative – 2D case: Laplacian The Laplacian is defined as: (dot product) Approximate 2nd partial derivatives:
  • 49. Second Derivative – 2D case: Laplacian (cont’d) Laplacian Mask Edges can be found by detecting the zero- crossings input image output image 5 5 5 5 5 -5 -5 -10 -10 -10 10
  • 50. Second Derivative – 2D case: Laplacian (cont’d) • Other realizations of the Laplacian mask found in practice.
  • 51. Visualize the results of the Laplacian • Add the results of the Laplacian to the original image for better visualization 2 2 2 ( , ) ( , ) ( , ) where, ( , ) is input image, ( , ) is sharpenend images, -1 if ( , ) has a negative center value and 1 if ( , ) has a positive center value. g x y f x y c f x y f x y g x y c f x y c f x y           
  • 52. Visualize the results of the Laplacian (cont’d) no normalization, negative values clipped to zero blurred image scaled to [0, 255] Example:
  • 53. Laplacian vs Gradient Laplacian Sobel • Laplacian localizes edges better (zero-crossings). • Higher order derivatives are typically more sensitive to noise. • Laplacian is less computational expensive (i.e., one mask). • Laplacian can provide edge magnitude information but no information about edge direction.
  • 57. Quiz #2 • When: October 2, 2023 • What: Arithmetic, Logical and Geometric Transformations, Spatial Transformations