0% found this document useful (0 votes)
31 views37 pages

Tutorial 1 - Spatial Filtering Part 1

Uploaded by

Habiba Yasser
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)
31 views37 pages

Tutorial 1 - Spatial Filtering Part 1

Uploaded by

Habiba Yasser
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/ 37

DIGITAL IMAGE PROCESSING

TUTORIAL 1

Image Enhancement in Spatial Domain


Part 1
AGENDA

❑ Introduction to Image Processing.


❑ Image Enhancement in Spatial Domain.
❑ Smoothing Filters
❑ Sharpening Filters
❑ Sheet 1 (Q1 → Q4).
Image Processing and Computer Vision

➢ Image Processing
It is a method to perform some operations on an image, in order
to get an enhanced image or to extract some useful information
from it (eg: recognition of individual objects).

➢ Computer Vision
It is a field of computer science that deals with how computers can
gain high-level understanding from digital images or videos in the
same way that human vision does, and then provide appropriate
output.
Digital Image

▪ It is a representation of a two-dimensional
picture.

▪ Image (as a signal) is continuous in:

x- and y-coordinates → requires sampling


intensity → requires quantization

▪ Quality depends on the number of samples


and discrete intensity levels used in
sampling and quantization.
Image Representation

➢ Digital Image Representation


The image is represented as an array of M
rows and N columns of pixels each storing a
value f(x,y).

M rows

➢ Pixel
N columns
It denotes the elements of a digital image.
Digital Image Types

➢ Binary Image
2D array of integer numbers where each pixel intensity has two
possible values (0,1) or (0, 255) for an 8-bit image.

➢ Grayscale Image
2D array of integer numbers where each pixel has a value most
commonly in range [0-255] for an 8-bit image.

➢ RGB Image
3D array that defines red, green, and blue color components
for each individual pixel. Each of the three values is in the
range [0-255] for an 8-bit image.
Image Enhancement in Spatial Domain
➢ Image Enhancement
Image enhancement is the process of making images more
useful visually.
• Highlight interesting details.
• Removing noise.

➢ Spatial Filtering
For any specific location (x, y), the value of g at filter

that location is the result of applying an


operation to the pixels in the neighborhood
using filters.
Filter
➢ Filter
Usually a rectangle which is slided over the image pixel
by pixel. This process is called correlation.

Filter may have different sizes ranging from 3x3, 5x5,


7x7,...21x21 pixels, even higher according to the image
or type of filtering you want to perform.

filter
Spatial Filtering Example
Spatial Filtering Example
Linear vs Non-linear Filters

A filter is called linear/non-linear when the operator being


used is linear/non-linear.

Example
z = 5a -3b + 2c linear
z = max(a, b) non-linear filter
Filter Types

1. Smoothing Filter (low pass filter)

2. Sharpening Filter (Edge Detector) (high pass filter).


1. Smoothing Filter

➢ Used for
1. Blurring and noise reduction.
2. Removing small details prior to object extraction.
3. Bridging small gaps in lines and curves.

➢ Includes
A. Averaging Filters.
B. Order-Statistics Filters.
- Median Filter.
- Maximum Filter.
- Minimum Filter.
1.A Averaging Filter

▪ One of the simplest linear spatial filters.


▪ Output = average of all the pixels in a neighbourhood.
➢ Conditions
• The elements of the filter must be positive.
Gaussian filter
• Filter elements sum to 1 assuming normalized weights
(i.e., divide each weight by the sum of weights).
So that if the filter is applied on a smooth image, it
doesn’t change it.
➢ Hyperparameters
1. Filter size (3x3, 5x5, ….). As the filter size
increases, the level of blurriness increases.
2. Filter weights.
1.B.a Median Filter

▪ A non-linear spatial filter.


▪ Output = median of all the pixels in a neighbourhood.
(Sort the pixels in the neighbourhood and select the median
(middle element).
▪ Forces points with distinct intensity levels to be like their
neighbors.
▪ Excellent for removing salt and pepper noise.
1.B.b Maximum Filter

▪ A non-linear spatial filter.


▪ Output = max of all the pixels in a
neighbourhood.
(Sort the pixels in the neighbourhood and
select the maximum).

▪ Useful for removing pepper noise.


Max = 250
1.B.c Minimum Filter

▪ A non-linear spatial filter.


▪ Output = min of all the pixels in a
neighbourhood.
(Sort the pixels in the neighbourhood and
select the minimum).

▪ Useful for removing salt noise. Min = 10


2. Sharpening Filter

➢ Used for
1. Highlight transitions in intensities→ highlight
edges.
2. Remove blurring → enhance details.

➢ Includes
A. Gradient Filter (First Derivative).
B. Laplacian Filter (Second Derivative).
2. Sharpening Filter

➢ Conditions
1. The elements of the filter contain both
positive and negative weights.
2. Filter elements sum to 0.

So that if the filter is applied on a smooth


image, the output = 0.

➢ Hyperparameters
1. Filter size (3x3, 5x5, ….).
2. Filter weights.
2. Sharpening Filter
2.A Gradient Filter

➢ Formula  f 
f Gx   x 
= f ( x + 1) − f ( x) Thus, f =   =  f 
x G y   
 y 
▪ Gradient magnitude: provides information
about edge strength.

▪ Gradient direction: perpendicular to the


direction of the edge (useful for tracing
object boundaries).

Usually, edges are detected by a local maxima


or minima of the first derivative.
2.A Gradient Filter
➢ Gradient filters
▪ Prewitt Filter

▪ Sobel Filter
2.B Laplacian Filter

➢ Formula

▪ In x-direction: 2 f
= f ( x + 1, y ) + f ( x − 1, y ) − 2 f ( x, y )
 x
2

▪ In y-direction: 2 f
= f ( x, y + 1) + f ( x, y − 1) − 2 f ( x, y )
 y
2

▪ Thus, Laplacian is given by:

▪ It is a linear filter. edges are detected by a zero-crossing.


2.B Laplacian Filter

➢ Sharpened Image using Laplacian

▪ Use the formula:

Let
• c = 1 if the filter’s center is positive.
• c = -1 if the filter’s center is negative.

Laplacian variants
2.B Laplacian Filter

➢ Sharpened Image using Laplacian


▪ The following formula can be represented by
the following filter:

Where f(x,y) can be obtained by a filter whose


center = 1 and other elements equal 0.
2. Gradient vs Laplacian Filter

• 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.
Sheet 1
(Q1 → Q4)
Question 1
Question 1
Question 2
Question 2
Question 3
Question 3
Question 3
Question 3
Question 4
Question 4

You might also like