Image Filtering 1

You might also like

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

Image Filtering

Spatial domain
Spatial Filtering
• Main idea
• Define a neighborhood of a pixel
• Define an operation on pixels in the neighborhood
• Output pixel value = result of the operation
• Topics
• Linear filtering
• Correlation, convolution
• Normalized cross correlation for recognizing objects
• Important examples
• Smoothing filters (box, average, Gaussian)
• Sharpening filters (Laplacian, Sobel)
• Non-linear filters
• Order-statistics filters (primarily median filter)
Linear Spatial Filtering
• Create a filter or mask w, size m × 𝑛
• Apply to image f, size M × 𝑁
• Compute the sum of products of mask coefficient with corresponding
pixels under mask
• Slide mask over image, apply at each point

• It is a linear operation
Spatial Filtering
• Different types:
• Smoothing filter
• Sharpening filter
• Smoothing filter
• Smoothing High frequency signal
• Noise (high frequency signal) reduction
• Disadvantage: edge blurring
Sharpening Spatial Filters
• The concept of sharpening filter
• First and second order derivatives
• Laplace filter
• Unsharp mask
• High boost filter
• Gradient mask
Smoothing
• Smoothing is often used to reduce noise within an image

• It takes into account the pixels surrounding it in order to make a


determination of a more accurate version of this pixel

• Unfortunately, extreme pixels can also represent original fine details,


which can also be lost due to the smoothing process
Smoothing
Smoothing Linear Filters
• Smoothing linear spatial filter is the average of the pixels contained in
the neighborhood of the filter mask

• Averaging filters or low pass filters


• Mean filter
• Gaussian filter
Mean Filter / Box Filter
• Mean filtering is simply to replace each pixel value in an image with
the mean (‘average’) value of its neighbors, including itself.
• 3× 3 normalized box filter
Example
• Normalize box filter
(different variant)
• 3×3 averaging filter
0 0 0 0 0 0 0
0 1 2 3 3 3
0 2 4 6 6 6
0 3 6 9 9 9
0 3 6 9 9 9
0 3 6 9 9 9
0
Mean Filter / Box Filter
• Image smoothed with 3× 3 , 5× 5 , 9× 9 , 11 × 11 box filters

• Drawback:
• Smoothing reduces fine image detail
Smoothing Filter
• The threshold as a multiple of the standard deviation of brightness
within the template window
Gaussian Filter

Gaussian Filter

Gaussian Filter

Gaussian Filter

Smoothing Non Linear Filters

Min and Max Filter

Median Filter

Comparison of Median and Box Filter

Midpoint Filter

Smoothing Filter
• Edge preserving smoothing:
Sharpening Spatial Filters
Sharpening Spatial Filters
• To highlight fine detail in an image or to enhance detail that has been
blurred either in error or as a natural effect of a particular method of
image acquisition.

• Blurring vs Sharpening
• Blurring/smooth is done in spatial domain by pixel averaging in a neighbors, it
is a process of integration
• Sharpening is an inverse process, to find the difference by the neighborhood,
done by spatial differentiation.
Gradient
• Image differentiation
• enhances edges and other discontinuities (noise)
• reduce the importance area with slowly varying gray-level values.

• The strength of the response of derivative operator is proportional to


the degree of operator is proportional to the degree of discontinuity
of the image at the point at which the operator is applied.
Gradient
Gradient
Gradient
Gradient
Gradient
Gradient Mask
• Roberts cross-gradient operators 2×2
Gradient Mask
• Sobel operators 3×3
Example
Gradient
• Second Order Differentials
First and second order difference of 1D
• The basic definition of the first-order derivative of a one dimensional
function f(x) is the difference

• The second-order derivative of a one-dimensional function f(x) is the


difference
First and second order difference of 2D
• when we consider an image function of two variables, f(x, y), at which
time we will dealing with partial derivatives along the two spatial
axes.
Discrete form of Laplacian
Result Laplacian Mask
Effect of Laplacian Operator
• as it is a derivative operator,
• it highlights gray-level discontinuities in an image
• it deemphasizes regions with slowly varying gray levels
• tends to produce images that have
• grayish edge lines and other discontinuities, all superimposed on a
dark,
• featureless background.
Correct the effect of featureless background
• easily by adding the original and Laplacian image.
• be careful with the Laplacian filter used
Example
Mask of Laplacian + addition
• To simply the computation, we can create a mask which do both
operations, Laplacian Filter and addition the original image.
Example
Example
Note:
Unsharp Masking
Unsharp Masking
Unsharp Masking
High-Boost filtering
High-Boost Masks
Example
Example of Combining Spatial Enhancement
Methods
• Want to sharpen the original image
and bring out more skeletal detail
• Problems: narrow dynamic range of
gray level and high noise content
makes the image difficult to enhance
Example of Combining Spatial Enhancement
Methods
• Solve
• Laplacian to highlight fine detail
• Gradient to enhance prominent edges
• Gray-level transformation to increase the dynamic range
of gray levels
• Power law
transformation=Gam
ma transformation
Vector Representation of Correlation
• Correlation is a sum of products of
corresponding terms

• We can think of correlation as a dot


product of vectors w and f

• A maximum dot product when the


vectors are aligned (𝜽 = 𝟎)

• If images w and f are similar, their


vectors are aligned
Correlation can do matching
Template Matching
• Since f is not constant everywhere, we need to normalize with
magnitude of w and f

• The result is between 0…1 (for positive valued images)


• We can get better precision by subtracting off means (𝑤,
ഥ 𝑓 )ҧ

This is the normalized


correlation coefficient
• The result is between -1……+1 (+1:the mask perfectly matches the image
and -1 means the mask perfectly opposite the image)
Normalized cross-correlation

Look for peak in


correlation score matrix
Correlation and Convolution
• Correlation • Convolution is very
similar to correlation,
except that we flip one
of the functions

• Also a linear operation


• Convolution

• Note that

• So to implement convolution we can reflect w(x, y) and then do


correlation
Normalized cross-correlation
• Exercise 2: Matching with normalized cross-correlation
• Don’t use prepared functions!!

You might also like