0% found this document useful (0 votes)
27 views

03.DIP. Filtering

The document discusses digital image processing fundamentals including spatial filtering. It covers histogram computation and equalization. Spatial filters including smoothing and sharpening filters are described. Smoothing filters like Gaussian filters reduce noise while sharpening filters like unsharp masking and highboost filtering highlight edges. Order-statistic filters like the median filter remove impulse noise. Gradient operators including Sobel and Roberts are used for edge detection and image enhancement. Assignments on image I/O, histogram computation, contrast stretching, and basic filtering are provided.

Uploaded by

Meii Quỳnh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

03.DIP. Filtering

The document discusses digital image processing fundamentals including spatial filtering. It covers histogram computation and equalization. Spatial filters including smoothing and sharpening filters are described. Smoothing filters like Gaussian filters reduce noise while sharpening filters like unsharp masking and highboost filtering highlight edges. Order-statistic filters like the median filter remove impulse noise. Gradient operators including Sobel and Roberts are used for edge detection and image enhancement. Assignments on image I/O, histogram computation, contrast stretching, and basic filtering are provided.

Uploaded by

Meii Quỳnh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Digital Image Processing

Fundamentals

Thanh-Hai Tran

Electronics and Computer Engineering


School of Electronics and Telecommunications
Hanoi University of Science and Technology
1 Dai Co Viet - Hanoi - Vietnam
Outline
n Histogram revision
n Introduction to spatial filtering
n Smoothing filters
n Sharpening filters
n References

2020 2
Histogram revision

n Given an image as illustrated in the figure


u Compute the histogram of this image
u Equalize the histogram and the converted image

2020 3
Histogram implementation

n Given an image represented as 2D array I[H][W]


n Compute the histogram of this image and normalize it

2020 4
Introduction

n Filtering is one of the principal tools used in DIP for a


broad spectrum of applications
n It is highly advisable that you develop a solid
understanding of these concepts.
n Filter is borrowed from frequency domain processing
n Filter refers to accepting (passing) or rejecting certain
frequency components
n Spatial filtering is applying filter on spatial domain

2020 5
The mechanics of spatial filter

n A spatial filter
u Neighborhood: small rectangle
u Pre-defined operation: linear and non-linear
n Filtering creates a new pixel
u with coordinates equal to the coordinates of the center of the
neighborhood,
u and whose value is the result of the filtering operation
n A processed (filtered) image is generated as the
center of the filter visits each pixel in the input image

2020 6
The mechanics of spatial filter

n Notation:
u f(x,y) is the original image
u w(x,y) is a filter mask
u g(x,y) is the filtered image
n At any point (x, y) in the image, the response, g(x, y) is
the sum of products of the filter coefficients and the
image pixels encompassed by the filter

n A general case, w has MxN size then a = M/2, b = N/2

2020 7
The mechanics of spatial filter

2020 8
Spatial correlation and convolution

n Correlation: is the process of moving a filter mask over


the image and computing the sum of products at each
location
n Convolution: the principle is the same but the filter is is
first rotated by 180°

2020 9
2020 10
Vector representation of linear filtering

n A filter of size mxn


will be represented
as

n When m = n = 3

2020 11
Generating Spatial Filter Masks

n Generating an mxn linear spatial filter requires that we


specify mxn mask coefficients.
n These coefficients are selected based on what the filter is
supposed to do,
n All we can do with linear filtering is to implement a sum of
products
n For example:
u Replace the pixels in an image by the average intensity of a
3 * 3 neighborhood centered on those pixels.
u The average value at any location (x, y) in the image is the
sum of the nine intensity values in the 3 * 3 neighborhood
centered on (x, y) divided by 9

2020 12
Generating Spatial Filter Masks

n In some applications, we have a continuous function of


two variables, and the objective is to obtain a spatial filter
mask based on that function
n For example, a Gaussian function of two variables has the
basic form

n Solution:
u We sample it about its center
u w1 = h(-1, -1), w2 = h(-1, 0), .. , w9 = h(1, 1)

2020 13
Designing Gaussian Filters
!𝟐 #$𝟐
! 𝟐
n 𝒈 i, j = c e 𝟐𝝈

n c is a normalizing constant
n 𝝈𝟐 = 2, n = 7

2020
Example of other Gaussian Filters

2020
Smoothing Spatial Filters

n Idea:
u Replacing the value of every pixel in an image by the
average of the intensity values in th neighborhood defined
by mask center
u It resuls in an image with reduced sharp transition
n Smoothing Spatial Filters are used for blurring or noise
reduction
n These filters are called averaging filters / lowpass filters
n Side effect: edges are blurred too.

2020 16
Smoothing Spatial Filters

2020 17
Example

2020 18
Example

2020
Order-statistic (non-linear) filters

n Order-statistic filters are nonlinear spatial filters whose


response is based on ordering (ranking) the pixels
contained in the image area encompassed by the filter,
n and then replacing the value of the center pixel with the
value determined by the ranking result
n The best-known filter in this category is the median filter
n Median filters are particularly effective in the presence of
impulse noise, also called salt-and-pepper noise because
of its appearance as white and black dots superimposed
on an image

2020 20
Order-statistic (non-linear) filters

n Median filter 3x3

2020 21
Order-statistic (non-linear) filters

n Median filter 3x3


u Neighbourhood: (10, 20, 20, 20, 15, 20, 20, 25, 100)
u Sorted: (10, 15, 20, 20, 20, 20, 20, 25, 100)

2020 22
Example

n An 8x8 image f(i,j) has gray levels given by the following


equation: f[i, j] =|i-j| with i, j =0,1,2,3,4,5,6,7
n Illustrate the matrix representing the image
n Apply a 3x3 median filter on this image, find the output
image; note that the border pixels remain unchanged.

2020 23
Sharpening Spatial Filters

n The principal objective of sharpening is to highlight


transitions in intensity.
n Uses of image sharpening: electronic printing and
medical imaging to industrial inspection and autonomous
guidance in military systems.
n Foundation of sharpening spatial filter
u We focus attention initially on one-dimensional derivatives
u Behavior of these derivatives in areas of constant intensity,
at the onset and end of discontinuities
u The derivatives of a digital function are defined in terms of
differences.

2020 24
First and second derivatives

2020
The Laplacian for Image Sharpening

n Laplacian:

2020 26
The Laplacian – Mask 3x3

n f(x, y) and g(x, y) are


the input and
sharpened images,
respectively.
n The constant is
u c = -1 if the Laplacian
filters (first row)
u c = 1 if either of the
other two filters is
used (second row)

2020
Example

Original image

2020
Unsharp masking and Highboost Filtering

n A process that has been used for many years by the


printing and publishing industry
n Sharpening images consists of subtracting an unsharp
(smoothed) version of an image from the original image
n This process, called unsharp masking, consists of the
following steps
u Step 1: Blur the original image.
u Step 2: Subtract the blurred image from the original (the
resulting difference is called the mask.
u Step 3: Add the mask to the original.

2020 29
Unsharp masking

n Letting f(x, y) denote


the blurred image
u k = 1: unsharp masking
u k > 1: highboost filtering
u 0< k < 1:de-emphasizes
the contribution of the
un- sharp mask

2020 30
Unsharp masking

2020 31
First order derivative for sharpening

n First derivatives in image processing are implemented


using the magnitude of the gradient
n For a function f(x, y), the gradient of f at coordinates (x, y)
is de- fined as the two-dimensional column vector

2020 32
gradient operators

n Roberts cross

n Sobel operators

2020 33
Gradient for image enhancement

(a) Optical image of contact lens (note defects on the boundary at


4 and 5 o’clock). (b) Sobel gradient. (Original image courtesy of
2020 Pete Sites, Perceptics Corporation.)
References

n Chapter 2, 3 - Digital Image Processing

2020 35
Assigment 1 (week 1-2-3)

n Read, display and write an image using OpenCV


n Write a function to compute the histogram of an image
and display the histogram
n Write a function to stretch constrast of an image
n Write a function to (3x3) filter an image, display and write
the output image:
u Median filter
u Smoothing filter (Gaussian)
u Sharpening filter (Laplacian)
n You can implement in C/C++ or python/ java
n Don’t use the pre-defined functions of the library

2020 36

You might also like