0% found this document useful (0 votes)
9 views469 pages

Notes Dip Full

The document provides an overview of digital image processing, covering its fundamentals, applications, and key processes such as image acquisition, sampling, and quantization. It highlights the differences between analog and digital images, the importance of image resolution, and various applications in fields like medicine and remote sensing. Additionally, it discusses key stages in digital image processing, including image enhancement, segmentation, and recognition.

Uploaded by

mrvikasyadav555
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)
9 views469 pages

Notes Dip Full

The document provides an overview of digital image processing, covering its fundamentals, applications, and key processes such as image acquisition, sampling, and quantization. It highlights the differences between analog and digital images, the importance of image resolution, and various applications in fields like medicine and remote sensing. Additionally, it discusses key stages in digital image processing, including image enhancement, segmentation, and recognition.

Uploaded by

mrvikasyadav555
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/ 469

GLA UNIVERSITY

DIGITAL IMAGE PROCESSING

By:
Dr. Ankush Agarwal
Outline

• Introduction and Fundamentals:


– Motivation and Perspective, Applications, Components of Image
Processing System,
– Element of Visual Perception, A Simple Image Model,
– Sampling and Quantization, Some Basic Relationships between Pixels
• Intensity Transformations and Spatial Filtering:
– Introduction, Some Basic Intensity Transformation Functions,
– Histogram Processing, Histogram Equalization, Histogram Specification,
– Local Enhancement, Enhancement using Arithmetic/Logic Operations
– Basics of Spatial Filtering, Smoothing, Sharpening
• Filtering in the Frequency Domain:
– Fourier Transform and the Frequency Domain,
– Basis of Filtering in Frequency Domain
© ankush agarwal 2
INTRODUCTION AND FUNDAMENTALS

© ankush agarwal 3
Image

• An image is a visual representation of scene


• It plays an important role in various applications areas such as
research and technology
• An image is an item that depicts visual perception such as a
photograph
• An image is a 2-D representation of a 3-D scene
• In the context of signal processing, an image is a collection of
distributed amplitude of color(s)

© ankush agarwal 4
Digital Image

• A digital image is a binary representation of visual information


• A digital image is a representation in a two dimensional space as
a finite set of digital values, called picture elements or pixels

© ankush agarwal 5
Difference

• Analog Image
– It represents the continuous range of values
– Eg: Image produced by CRT monitor

• Digital Image
– It represents the discrete values
– It is composed of picture elements called pixels

© ankush agarwal 4
Image Acquisition

• Images captured by sensors have an involvement of various


components
A D
– Source of electromagnetic energy
– Interaction with the Atmosphere
– Interaction with the Target
– Energy Recording by Sensor
B

C
© ankush agarwal 7
Process involved in Digital Image

• Output of most sensors is a continuous voltage waveform whose


amplitude & spatial behavior are related to the physical
phenomenon (e.g. brightness) being sensed
• For an image to be processed by a computer, it must be
represented by an appropriate discrete data structure (e.g. Matrix)
• Two important processes to convert continuous analog image into
digital image
– Sampling
– Quantization

© ankush agarwal 8
Process involved in Digital Image

© ankush agarwal 9
Process involved in Digital Image

• To convert an image to digital form, we have to sample the image


in both coordinates (spatial domain) and in amplitude

• Discretization
– Process in which signals or data samples are considered at regular
intervals
• Sampling
– It is the discretization of image data in spatial coordinates or defining
finite discrete coordinate to every part of an image
• Quantization
– It is the discretization of image intensity (gray level) values or defining
finite value to every discrete interval

© ankush agarwal 10
Sampling and Quantization

© ankush agarwal 11
Sampling and Quantization

© ankush agarwal 11
Sampling and Quantization

© ankush agarwal 11
Sampling and Quantization

before after
© ankush agarwal 12
Sensor Arrangement

• Single imaging sensor

© ankush agarwal 13
Sensor Arrangement

• Single imaging sensor


• Line sensor

© ankush agarwal 13
Sensor Arrangement

• Single imaging sensor


• Line sensor
• Array sensor

© ankush agarwal 13
Digital Image Representation

• Monochrome image can be represented as a two dimensional light


intensity function f(x, y)
– where
• x & y are spatial coordinates
• the value of f at point (x, y) is the gray level or the brightness of the image

• For computer storage, an array with the number of gray levels


should be in the power of 2
• A typical gray level image contains 256 shades of gray (8 bit)
• Values are stored between 0 - 255

© ankush agarwal 14
Digital Image Representation

• The intensity of a monochrome image at any coordinate (xi, yi) is


called the gray level (ii) of the image, which is given by
ii = f(xi, yi)
– 0 ≤ i ≤ Lmax - 1
– i = 0 is considered black
– i = Lmax - 1 is considered white

© ankush agarwal 15
Image Samples

• Generally, image is of size m x n


– where,
• m: number of rows and
• n: number of columns
• The no. of gray level values (L), is taken as power of 2
• L = 2k
– where,
• k: number of bits used for representation

© ankush agarwal 16
Image Size

• For an image of size m x n, if k are the number of bits for representation, then
Image size = m x n x k

© ankush agarwal 17
Image Size

• Eg:
– For an image of 512 by 512 pixels, with 8 bits per pixel

Solution
Size = 512 * 512 * 8 bits
= 29 * 29 * 23 bits
= 221/23 bytes
= 218/210 K bytes
= 256 KB

© ankush agarwal 18
Image Size

• Eg:
– For an image of 64 by 64 pixels with 3 bands, with 4 bits per pixel

Solution
Discuss in class

© ankush agarwal 19
Image Size

• Eg:
– For an image of 32 by 32 pixels with 4 bands, in which the smallest unit
of an image consists of 11 shades

Solution
Discuss in class

© ankush agarwal 19
Image Size

• Eg:
– For an image of 10x10x6, the pixels can represent 8 shades

Solution
Discuss in class

© ankush agarwal 19
Image Size

• Eg:
– For an image of 25 by 30 pixels with 5 spectral, the pixels have 17 levels

Solution
Discuss in class

© ankush agarwal 19
Motivation

• The human brain is unequalled in 2D image analysis and image


understanding

• Limitations of the human visual system


– Quantification
– Reconstruction of 3D scenes
– High dimensional image spaces

• Practical applications
– Quantitative measurements
– Automatic analysis of images

© ankush agarwal 20
Perspective

• Digital image processing deals with manipulation of digital images


through a digital computer
• It is a subfield of signals and systems but focus particularly on
images
• DIP focuses on developing a computer system that is able to
perform processing on an image
• The input of that system is a digital image and the system
process that image using efficient algorithms, and gives an image
as an output

© ankush agarwal 21
Applications

• Some of the major fields in which digital image processing is


widely used are
– Medical field

© ankush agarwal 22
Applications

• Some of the major fields in which digital image processing is


widely used are
– Medical field
– GIS

© ankush agarwal 22
Applications

• Some of the major fields in which digital image processing is


widely used are
– Medical field
– GIS
– Remote sensing

© ankush agarwal 22
Applications

• Some of the major fields in which digital image processing is


widely used are
– Medical field
– GIS
– Remote sensing
– Object tracking

© ankush agarwal 22
Applications

• Some of the major fields in which digital image processing is


widely used are
– Medical field
– GIS
– Remote sensing
– Object tracking
– Classification

© ankush agarwal 22
Applications

• Some of the major fields in which digital image processing is


widely used are
– Medical field
– GIS
– Remote sensing
– Object tracking
– Classification
– Change detection

© ankush agarwal 22
Applications

• Some of the major fields in which digital image processing is


widely used are
– Medical field
– GIS
– Remote sensing
– Object tracking
– Classification
– Change detection
– Disaster monitoring

© ankush agarwal 22
Applications

• Some of the major fields in which digital image processing is


widely used are
– Medical field
– GIS
– Remote sensing
– Object tracking
– Classification
– Change detection
– Disaster monitoring
– etc

© ankush agarwal 22
Image Sensing

• Sensing operates in various region of Electro Magnetic Spectrum

© ankush agarwal 23
Image Resolutions

• There are four types of resolution


– Spatial resolution
– Spectral resolution
– Temporal resolution
– Radiometric resolution

© ankush agarwal 24
Spatial Resolution

• The smallest possible feature that can be detected in an image


OR
• The size of single pixel or area covered by a single pixel (GSD)

© ankush agarwal 25
Spatial Resolution

 16 x 16
 32 x 32
 64 x 64
 128 x 128

 256 x 256

 512 x 512

© ankush agarwal 26
Spatial Resolution

© ankush agarwal 27
Spatial Resolution

© ankush agarwal 28
Various sensors image

MODIS (250 m) LANDSAT 8 (30 m) SENTINEL 2 (10 m) DRONE (0.05 m)

© ankush agarwal 29
Spectral Resolution

• It describes the capability of a sensor to capture information in


various bands which have fine wavelength intervals
• Information recorded by the sensor in various bands are referred
as multi-spectral sensors

© ankush agarwal 30
Spectral Resolution

© ankush agarwal 32
Temporal Resolution

• The concept of revisit period is important for monitoring that help


us to identify the changes over a period of time
• Time taken by a sensor to locate exact same area second time at
same interval time is considered as temporal resolution

© ankush agarwal 33
Temporal Resolution
Sentinel-2
RGB

Central Coordinates: 29.929831°N, 77.964490°E © ankush agarwal 34


Temporal Resolution
Sentinel-2
Classified

Bare Land Dense Vegetation Sparse Vegetation

Central Coordinates: 29.929831°N, 77.964490°E © ankush agarwal 34


Temporal Resolution

© ankush agarwal 35
Radiometric Resolution

• Image captured by sensor have certain characteristics which can


be improved later
• This is a part of radiometric resolution which helps to enhance
the pixel characteristics, which ultimately help to identify very
slight difference in an image
• It depends on the ability of sensor
• Sensor having greater radiometric property is more sensitive to
detect changes
• It is the smallest visible change in the gray level of an image

© ankush agarwal 36
Radiometric Resolution

© ankush agarwal 37
Type of effects

• There are two type of effects


– Checkerboard effect
• When the no. of pixels in an image is reduced by keeping the no. of gray levels in
the image constant, fine checkerboard patterns are found at the edges of the
image

– False contouring effect


• When the no. of gray-levels in the image is low, the foreground details of the
image merge with the background details of the image, causing ridge like
structures. This degradation phenomenon is known as false contouring

© ankush agarwal 38
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 39
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 40
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 41
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 41
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 42
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 42
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 43
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 44
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 44
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 45
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 46
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 46
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 47
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 48
Key Stages in Digital Image Processing

Image Morphological
Segmentation
Restoration Processing

Image Object
Enhancement Recognition

Image Representation
Acquisition and Description

Color Image Image


Scene
Processing Compression

© ankush agarwal 48
Image types

Image Examples Image Formats Image Types


• X-ray Image • RAW • Bilevel
• Ultrasound • BMP • GrayScale
Images • GIF • True Color
• CT Scan Images • JPG • False Color
• MR Images • TIFF • MultiSpectral
• Satellite Images • HDF • HyperSpectral
• Thermal Images • etc… • etc…
• Radar Images
• etc…
© ankush agarwal 58
Types of Images

© ankush agarwal 59
Types of Images

Original Images Pseudo Color Binary Image

© ankush agarwal 60
Aspect Ratio

• An aspect ratio is a proportional relationship between an image's


width and height

© ankush agarwal 61
Aspect Ratio

• Eg:
– If we want to resize a 1024x768 image to one that is 600 pixels wide with
the same aspect ratio as the original image, what should be the height of
the resized image?

Solution
Aspect Ratio = width/height
= 1024/768
= 1.33
Height = 600/1.33
= 451
© ankush agarwal 62
Aspect Ratio

• Eg:
– Suppose, we have an image that have 16 rows and have a aspect ratio of 1
or 1:1. Find the total number of pixels in the image.

Solution
in class

© ankush agarwal 63
Aspect Ratio

• Eg:
– Suppose, an image have an aspect ratio of 3:2 with a width of 36 mm.
Find the height of the image.

Solution
in class

© ankush agarwal 64
Baud Rate

• A common measure of transmission for digital data


• It is the no. of bits transmitted per second
• Generally transmission is accomplished in packets consisting of a
start bit, a byte of information & a stop bit

© ankush agarwal 65
Baud Rate

• Eg:
– How many minutes would it take to transmit a 1024 x 1024 image with
256 gray levels using a 56K baud rate?

Solution
Total no. of bits needed to represent the image: 1024 x 1024 x 8
No. of packets required: 1024 x 1024
Total no. of bits that need to be transferred: 1024 x 1024 x [8 + 2]
Total time required: 1024 x 1024 x [8 + 2]/56000
= 187.25 sec or 3.1 min

© ankush agarwal 66
Baud Rate

• Eg:
– Compute the time required to transmit an image of 64 x 64 with 32 gray
levels using a 20 b/s.

Solution
In class

© ankush agarwal 66
Baud Rate

• Eg:
– Compute the time required to transmit an image of 200 x 200 consists of
4 bands with 9 gray levels using a 10 b/s.

Solution
In class

© ankush agarwal 66
Baud Rate

• Eg:
– Compute the time required to transmit an image of 32 x 32 consists of 7
bands with 11 levels using a 7 b/s.

Solution
In class

© ankush agarwal 66
Baud Rate

• Eg:
– Compute the time required to transmit an image having a width of 200
and a aspect of 2:5 using a 7 b/s. It consists of 4 bands with 4 bits per
pixels.

Solution
In class

© ankush agarwal 66
Basic relationship between pixels

• An image is denoted by a function f(x, y)


• Each element f(x, y) at location (x, y) is called a pixel
• There exist some basic and important relationships between
pixels

© ankush agarwal 67
Basic relationship between pixels

• Neighborhood
• Adjacency
• Connectivity (i-1, j-1) (i-1, j) (i-1, j+1)

• Paths
• Regions and boundaries
(i, j-1) (i, j) (i, j+1)

(i+1, j-1) (i+1, j) (i+1, j+1)

© ankush agarwal 68
Basic relationship between pixels (Neighbours)

• A pixel p at location (x, y) has two horizontal and two vertical


neighbours
• This set of four pixels is called 4-neighbors of p = N4(p)
• Each of these neighbours is at a unit distance from p
• If p is a boundary pixel then it will have less number of
neighbours
(i-1, j)

p
(i, j-1) (i, j+1)
(i, j)

(i+1, j)

© ankush agarwal 69
Basic relationship between pixels (Neighbours)

• A pixel p has four diagonal neighbours ND(p)


• The union of N4(p) and ND(p) together are called 8-neighbors of p
N8(p) = N4(p) U ND(p)
• If p is a boundary pixel then both ND(p) and N8(p) will have less
number of pixels
(i-1, j-1) (i-1, j+1)

p
(i, j)

(i+1, j-1) (i+1, j+1)

© ankush agarwal 70
Basic relationship between pixels (Adjacency)

• Two pixels are said to be connected if they are adjacent in some


sense
– They are neighbours (N4, ND or N8) and
– Their intensity values (gray levels) are similar

• Two pixels are adjacent if they are neighbour and their intensity
level ‘V’ satisfy some specific criteria of similarity
• Let V be the set of intensity values

© ankush agarwal 71
Basic relationship between pixels (Adjacency)

• 4-adjacency: Two pixels p and q with values from set ‘V’ are 4-
adjacent if q is in the set N4(p)
• Eg:
– V = {0, 1}

1 1 0
1 1 0
1 0 1
© ankush agarwal 72
Basic relationship between pixels (Adjacency)

• 8-adjacency: Two pixels p and q with values from set ‘V’ are 8-
adjacent if q is in the set N8(p)
• Eg:
– V = {1, 2}

0 1 1
0 2 0
0 0 1
© ankush agarwal 73
Basic relationship between pixels (Adjacency)

• m-adjacency: Two pixels p and q with values from V are m-


adjacent if
– (i) q is in the set N4(p), Eg: V = {1} OR
– (ii) q is in the set ND(p) and the set N4(p) ∩ N4(q) is empty

• Eg:
0 1 1
0 1 0
0 0 1
© ankush agarwal 74
Basic relationship between pixels (Adjacency)

• m-adjacency: Two pixels p and q with values from V are m-


adjacent if
– (i) q is in the set N4(p), Eg: V = {1} OR
– (ii) q is in the set ND(p) and the set N4(p) ∩ N4(q) is empty

• Eg:
0 1 1
0 1 0
0 0 1
© ankush agarwal 74
Basic relationship between pixels (Adjacency)

• m-adjacency: Two pixels p and q with values from V are m-


adjacent if
– (i) q is in the set N4(p), Eg: V = {1} OR
– (ii) q is in the set ND(p) and the set N4(p) ∩ N4(q) is empty

• Eg:
0 1 1
0 1 0
0 0 1
© ankush agarwal 74
Basic relationship between pixels (Adjacency)

• m-adjacency: Two pixels p and q with values from V are m-


adjacent if
– (i) q is in the set N4(p), Eg: V = {1} OR
– (ii) q is in the set ND(p) and the set N4(p) ∩ N4(q) is empty

• Eg:
0 1 1
0 1 0
0 0 1
© ankush agarwal 74
Basic relationship between pixels (Adjacency)

• Eg:
– Find 4-adjacency and 8-adjacency of the center pixel
– Note: V = {1}

Solution
– 4-adjacency
0 1 1
0 1 0
0 0 1
© ankush agarwal 76
Basic relationship between pixels (Adjacency)

• Eg:
– Find 4-adjacency and 8-adjacency of the center pixel
– Note: V = {1}

Solution

– 8-adjacency
0 1 1
0 1 0
0 0 1
© ankush agarwal 76
Basic relationship between pixels (Connectivity)

• Let S represent a subset of pixels in an image


• Two pixels p with coordinates (x0, y0) and q with coordinates (xn,
yn) are said to be connected in S if there exists a path
(x0, y0), (x1, y1), …, (xn, yn)

© ankush agarwal 77
Basic relationship between pixels (Path)

• A path from pixel p with coordinates (x0, y0) to pixel q with


coordinates (xn, yn) is a sequence of distinct pixels with
coordinates (x0, y0), (x1, y1), …, (xn, yn)
– where (xi, yi) and (xi-1, yi-1) are adjacent for 1 ≤ i ≤ n
• Here n is the length of the path
• If (x0, y0) = (xn, yn), the path is closed path
• We can define 4-, 8-, and m-paths based on the type of adjacency
used

© ankush agarwal 78
Basic relationship between pixels (Path)

• Eg:
– Compute the length of shortest-4 path between pixels p and q, where V =
{1, 2}

Solution
4 2 3 2 q
x
3 3 1 3
2 3 2 2
p 2 1 2 3
© ankush agarwal 79
Basic relationship between pixels (Path)

• Eg:
– Compute the length of shortest-8 path between pixels p and q, where V =
{1, 2}

Solution
4 2 3 2 q
3 3 1 3
2 3 2 2
p 2 1 2 3
© ankush agarwal 80
Basic relationship between pixels (Path)

• Eg:
– Compute the length of shortest-m path between pixels p and q, where V =
{1, 2}

Solution
4 2 3 2 q
3 3 1 3
2 3 2 2
p 2 1 2 3
© ankush agarwal 81
Basic relationship between pixels (Region)

• Let R be a subset of pixels in an image, two regions Ri and Rj are


said to be adjacent if their union form a connected set
• Regions that are not connected are said to be disjoint
• We consider 4- and 8- adjacency when referring to the regions
• Eg:
Ri Rj
– V = {1}
1 1 0 0 1 1
1 0 1 0 1 1
1 1 0 1 1 1
• Regions are adjacent only if 8-adjacency is used

© ankush agarwal 82
Distance Measure

• Given pixels p(u, v), q(w, x) and r(y, z) with


coordinates, the distance function D has following
properties:
– D(p, q) ≥ 0 [D(p, q) = 0, iff p = q]
– D(p, q) = D(q, p)
– D(p, r) ≤ D(p, q) + D(q, r)

© ankush agarwal 83
Distance Measure

• The following are the different distance measures


– Euclidean Distance:
• De(p, q) = [(u-w)2 + (v-x)2]1/2 Pixel Coordinate
– City Block Distance:
• D4(p, q) = |u-w| + |v-x|
p (u, v)
– Chess Board Distance: q (w, x)
• D8(p, q) = max(|u-w|, |v-x|)

© ankush agarwal 84
Distance Measure (Euclidean Distance)

• For distance measure, the pixels having a distance


less than or equal to some value from p(u, v) are the
points contained in a disk of radius (r) centered at p(u,
v)

© ankush agarwal 85
Distance Measure (City-block Distance)

• The pixels having a D4 distance from p(u, v) less than


or equal to some value, form a diamond centered at
p(u, v)
• The pixels with D4 =1 are the 4-neighbors of p(u, v)
2
2 1 2
2 1 0 1 2
2 1 2
2

© ankush agarwal 86
Distance Measure (Chessboard Distance)

• The pixels with D8 distance from p(u, v) less than or


equal to some value, form a square centered at p(u, v)
• The pixels with D8=1 are the 8-neighbors of (u, v)
2 2 2 2 2
2 1 1 1 2
2 1 0 1 2
2 1 1 1 2
2 2 2 2 2
© ankush agarwal 87
Some Mathematical Tools

• When we multiply two images, we usually carry out


array multiplication

© ankush agarwal 89
Some Mathematical Tools (Arithmetic Operations)

• Arithmetic operations are performed on the pixels of


two or more images
• Let p and q be the pixel values at location (x, y) in first
and second images respectively
– Addition: p + q
– Subtraction: p - q
– Multiplication: p.q
– Division: p/q

© ankush agarwal 92
Some Mathematical Tools (Mask Mode Radiography)

• One of the most successful commercial applications of


image subtraction

© ankush agarwal 93
Some Mathematical Tools

• Eg:
– Blood stream is injected with a dye and X-ray images are taken before
and after the injection
– f(x, y): image after injecting a dye
– h(x, y): image before injecting the dye

before injection after injection

© ankush agarwal 94
Some Mathematical Tools (Image Averaging)

• A noisy image:
g ( x, y )  f ( x, y )  n ( x, y )
• Averaging M different noisy images:
M
1
g ( x, y ) 
M
 g ( x, y )
i 1
i

• As M increases, the variability of the pixel values at each location


decreases
• This means that g(x, y) approaches f(x, y) as the number of noisy
images used in the averaging process increases

© ankush agarwal 95
Some Mathematical Tools (Shading Correction)

• An important applications of image division


• An imaging sensor produces image g(x, y), where
• g(x, y) = f(x, y) h(x, y)

• By dividing g(x, y) by h(x, y), we can get the perfect


image

© ankush agarwal 97
Some Mathematical Tools (Region of Interest)

• An important applications of image multiplication

© ankush agarwal 98
Some Mathematical Tools (Set Operations)

© ankush agarwal 99
Some Mathematical Tools (Logical Operations)

© ankush agarwal 100


Some Mathematical Tools (Logical Operations)

© ankush agarwal 100


Some Mathematical Tools (Logical Operations)

© ankush agarwal 100


Some Mathematical Tools (Logical Operations)

© ankush agarwal 100


Some Mathematical Tools (Logical Operations)

© ankush agarwal 100


RECAP

© ankush agarwal 97
Recap

• Digital Image
• Steps of Image Acquisition
– (4 steps)
• Process involved in Digital image
– (Sampling and Quantization)
• Sensor arrangement
– (Single, Line, Array)
• Levels in image
– (L = 2k)
• Image size
– (m x n x k)
• Applications of Image Processing
• Image sensing
– (EMS)
© ankush agarwal 97
Recap

• Types of resolutions
– (Spatial, Spectral, Temporal, Radiometric)
• Types of effect
– (Checkerboard, False contouring)
• Key stages of Image Processing
• Aspect ratio
– (r = w/h)
• Baud rate
• Relationship between pixels
– (Neighbour: N4, ND, N8, Adjacency: 4-, 8-, m-, Connectivity, Path: 4-, 8-, m-,
Region)
• Distance measure
– (Euclidean, City block, Chess board)
• Set operations
© ankush agarwal 97
GLA UNIVERSITY

DIGITAL IMAGE PROCESSING

By:
Dr. Ankush Agarwal
Outline

• Introduction and Fundamentals:


– Motivation and Perspective, Applications, Components of Image
Processing System,
– Element of Visual Perception, A Simple Image Model,
– Sampling and Quantization, Some Basic Relationships between Pixels
• Intensity Transformations and Spatial Filtering:
– Introduction, Some Basic Intensity Transformation Functions,
– Histogram Processing, Histogram Equalization, Histogram Specification,
– Local Enhancement, Enhancement using Arithmetic/Logic Operations
– Basics of Spatial Filtering, Smoothing, Sharpening
• Filtering in the Frequency Domain:
– Fourier Transform and the Frequency Domain,
– Basis of Filtering in Frequency Domain
© ankush agarwal 2
IMAGE ENHANCEMENT

© ankush agarwal 3
Image Enhancement

• Image enhancement is the process of making images


more useful
• The reasons for doing this include:
– Making images more visually appealing
– Highlighting interesting details in images
– Removing noise from images

© ankush agarwal 4
Image Enhancement

• Images may suffer from the following degradations:


– Poor contrast due to poor illumination
– Electronic sensor noise or atmospheric disturbances
– Aliasing effects due to inadequate sampling
– Finite aperture effects or motion

© ankush agarwal 5
Image Enhancement

• Applications of transformations
– Contrast enhancement
– Gray scale transformation
– Photometric calibration
– Display calibration
– Contour lines

© ankush agarwal 6
Image Enhancement

Image Enhancement

Frequency
Spatial Domain
Domain

Intensity Transformation

Spatial Filtering

© ankush agarwal 7
Image Enhancement

• There are two broad categories of image enhancement


approaches
– Spatial domain methods
• Based on direct manipulation of pixels in an image
– Frequency domain methods
• Based on modifying the fourier transform of an image

© ankush agarwal 8
Image Enhancement (Spatial domain)

• Intensity Transformations (Point processing)


– Operate on single pixels of an image
– Eg: image averaging; logic operation; contrast stretching
• Spatial Filtering (Mask processing)
– Working in a neighborhood of every pixel in an image
– Eg: blurring, median

© ankush agarwal 9
BASIC INTENSITY TRANSFORMATIONS

© ankush agarwal 11
Basic Intensity Transformations

• Linear transformations
– Image negative
• Non-linear transformations
– Logarithmic transformation
– Power Law (Exponential) transformation
• Piecewise-linear transformations
– Contrast stretching
– Gray-level slicing
– Bit plane slicing
• Histogram

© ankush agarwal 12
Image Enhancement (Spatial Intensity)

• T = gray level (or intensity or mapping) transformation


function
s = T(r)
– where
• r = gray level of f(x, y)
• s = gray level of g(x, y)

© ankush agarwal 13
Image Enhancement (Spatial Intensity)

• The intensity transformation is divided into further categories


– Linear function
• Negative and identity transformations
– Non-linear function
• Log and inverse-log transformation
• Power law function

© ankush agarwal 14
Image Enhancement (Spatial Intensity)

Linear  Negative transformation


• Reversing the intensity levels of an image
s = L – 1 –r

© ankush agarwal 15
Image Enhancement (Spatial Intensity)

Non linear  Log Transformations


s = c log (1+r)
• c is a constant
• Used to expand the values of dark pixels in an image while
compressing the higher-level values

© ankush agarwal 16
Image Enhancement (Spatial Intensity)

Non linear  Power-Law Transformations


s = crγ
• c and γ are positive constants
• Power-law curves with fractional values of γ map a narrow range
of dark input values into a wider range of output values, with the
opposite being true for higher values of input levels
• c = γ = 1  Identity function

© ankush agarwal 17
Image Enhancement (Spatial Intensity)

Non linear  Power-Law Transformations

• a) image has a washed-out appearance


• b) γ = 3.0 (suitable)
• c) γ = 4.0 (suitable)
• d) γ = 5.0 (some detail is lost)

© ankush agarwal 18
Image Enhancement (Spatial Intensity)

Piecewise-Linear Transformation
• A complementary approach to the previous methods
• Practical implementation of some important transformations can
be formulated only as piecewise functions

© ankush agarwal 19
Piecewise-Linear (Contrast Stretching)

• The simplest of piecewise linear functions is contrast stretching


• Basic idea is to increase the dynamic range of the gray levels in
the image
• During image acquisition, low contrast images may result due to
– Poor illumination
– Lack of dynamic range in image sensor
– Wrong setting of the lens aperture

© ankush agarwal 20
Piecewise-Linear (Contrast Stretching)

• (a) increase the dynamic range of the gray levels in the image
• (b) a low-contrast image
• (c) result of contrast stretching
– (r1, s1) = (rmin, 0)
– (r2, s2) = (rmax, L-1)
• (d) result of thresholding

© ankush agarwal 21
Image Enhancement (Spatial Intensity)

• The gray level below m are darkened and the levels above m are
brightened or vice-versa
• Produces a binary image from input image and the function is
known as thresholding function
g(x, y) = L if f(x, y) > m,
0 otherwise

© ankush agarwal 22
Piecewise-Linear (Gray level slicing)

• Highlight a specific range of gray values


• Two basic Methods
– Display a high value for all gray levels in the range of interest and a low value for all
other
– Brighten the desired range of gray levels but preserve all other levels

© ankush agarwal 23
Piecewise-Linear (Bit-plane slicing)

• Highlighting the contribution made to total image appearance by


specific bits
• Useful for analyzing the relative importance played by each bit of
the image

© ankush agarwal 25
Piecewise-Linear (Bit-plane slicing)

• Higher order bit planes of an image carry a significant amount of


details
• Lower order planes contribute more to fine details

© ankush agarwal 26
HISTOGRAM PROCESSING

© ankush agarwal 27
Histogram Processing

• Histogram is a discrete function formed by counting the number


of pixels that have a certain gray level in the image
• Histogram of a digital image with gray levels in the range [0, L-1]
is a discrete function
h(rk) = nk
– where
– rk: the kth gray level
– nk: the number of pixels in the image having gray level rk
– h(rk): histogram of a digital image with gray levels rk

© ankush agarwal 28
Histogram Processing

2 3 3 2
4 2 4 3
3 2 3 5
2 4 2 4

© ankush agarwal 29
Normalized Histogram

• Dividing each of histogram at gray level (rk) by the total number of


pixels in the image (n)
p(rk) = nk/n
– for k = 0, 1, …, L-1
– p(rk) gives an estimate of the probability of occurrence of gray level rk
– The sum of all components of a normalized histogram is equal to 1

© ankush agarwal 30
Histogram Processing

• Eg:
– An image with gray levels between 0 to 7 is given below. Find the
histogram of an image and normalize it

1 6 2 2
1 3 3 3
4 6 4 0
1 6 4 7

© ankush agarwal 31
Histogram Processing

• In the dark images, components of the histogram are


concentrated on the lower (dark) side of the gray scale

© ankush agarwal 32
Histogram Processing

• In the dark images, components of the histogram are


concentrated on the lower (dark) side of the gray scale
• In bright images, the histogram is biased towards the higher side
of the gray scale

© ankush agarwal 32
Histogram Processing

• In low contrast, the histogram will be narrow & centred towards


the middle of the gray scale

© ankush agarwal 33
Histogram Processing

• In low contrast, the histogram will be narrow & centred towards


the middle of the gray scale
• In high contrast, a large variety of gray tones occupy the entire
range of possible gray levels

© ankush agarwal 33
Histogram Equalization

• It is the process that transforms the intensity values so that the


histogram of the output image approximately matches the flat
(uniform) histogram
• The aim is to create an image with equally distributed brightness
levels over the whole brightness scale
• We can do it by adjusting the probability density function (pdf) of
the original histogram of the image so that the probability spread
equally

© ankush agarwal 34
Histogram Equalization

• Histogram equalization results are similar to contrast stretching


but offer the advantage of full automation
• HE automatically determines a transformation function to
produce a new image with a uniform histogram
• Goal
– find a transform s = T(r) such that the transformed image has a flat
(equalized) histogram
– where T(r) satisfies the following conditions:
• T(r) is single-valued and monotonically increasing in interval [0, 1]
• 0 ≤ T(r) ≤ 1 for 0 ≤ r ≤ 1

© ankush agarwal 35
Histogram Equalization

• The discrete transformation function is given by


s j  T (r j )
k
  p ( rj )
j 0
k nj
 k  0,1,..., L  1
j 0 n

© ankush agarwal 36
Histogram Equalization

• The following equations bring back the gray levels in the range [0, L-1]

s j  T (r j )
k
 (L 1) p(rj )
j 0
k nj
 (L 1)
j 0 MN
(L 1) k
• M – no. of rows  
MN j 0
nj k  0,1,..., L  1
• N – no. of columns
• MN – total no. of pixels in the image
© ankush agarwal 37
Histogram Equalization

• Eg:
– Suppose that a 3-bit image (L = 8) of size 64 × 64 pixels (MN = 4096) has
the intensity distribution shown in following table. Get the histogram
equalization transformation function and give the p(sk) for each sk

© ankush agarwal 38
Histogram Equalization

i/p Gray Level no. of pixels p(rk) = nk/MN Σ (L-1)Σ o/p Gray
(rk) (nk) Level (s)
0 790 0.19 0.19 1.33 1
1 1023 0.25 0.44 3.08 3
2 850 0.21 0.65 4.55 5
3 656 0.16 0.81 5.67 6
4 329 0.08 0.89 6.23 6
5 245 0.06 0.95 6.65 7
6 122 0.03 0.98 6.86 7
7 81 0.02 1.00 7.00 7
© ankush agarwal 39
Histogram Equalization

(rk) (nk) p(rk) Σ (L-1)Σ (sk) Equalized nk


0 790 0.19 0.19 1.33 1 0 0
1 1023 0.25 0.44 3.08 3 1 790
2 850 0.21 0.65 4.55 5 2 0
3 656 0.16 0.81 5.67 6 3 1023
4 329 0.08 0.89 6.23 6 4 0
5 245 0.06 0.95 6.65 7 5 850
6 122 0.03 0.98 6.86 7 6 656 + 329 = 985
7 81 0.02 1.00 7.00 7 7 245 + 122 + 81 = 448

© ankush agarwal 40
Histogram Equalization

© ankush agarwal 41
Histogram Matching (Specification)

• Histogram equalization has a disadvantage that it can generate


only one type of output image
• Sometimes it is useful to specify the shape of the histogram
• With histogram specification, we can specify the shape of the
histogram
• It doesn’t have to be a uniform histogram

• For an image, whose enhancement is to be done, we are given an


histogram, G(zk), that actually shows how the processed image’s
histogram should look after applying the transformation function
to the i/p image
© ankush agarwal 43
Histogram Matching (Specification)

• Step 1: Find histogram of input image p(rj), and find histogram


equalization mapping
• Step 2: Specify the desired histogram, and find histogram
equalization mapping
• Step 3: Build lookup table:
– For each gray level k, find sk and then find a level such that sk best
matches zq:
min|sk-zq|
– setup a lookup entry lookup[k] = q

© ankush agarwal 44
Histogram Matching (Specification)

• Eg:
– Suppose that a 3-bit image of size 64 × 64 pixels has the intensity
distribution shown in the table (on the left). Get the histogram
transformation function and make the output image with the specified
histogram, listed in the table on the right

© ankush agarwal 45
Histogram Matching (Specification)

(rk) (nk) p(rk) Σ (L-1)Σ (sk) (zk) p(zk) Σ (L-1)Σ G(zk)


0 790 0.19 0.19 1.33 1 0 0.00 0 0 0
1 1023 0.25 0.44 3.08 3 1 0.00 0 0 0
2 850 0.21 0.65 4.55 5 2 0.00 0 0 0
3 656 0.16 0.81 5.67 6 3 0.15 0.15 1.05 1
4 329 0.08 0.89 6.23 6 4 0.20 0.35 2.45 2
5 245 0.06 0.95 6.65 7 5 0.30 0.65 4.55 5
6 122 0.03 0.98 6.86 7 6 0.20 0.85 5.95 6
7 81 0.02 1.00 7.00 7 7 0.15 1 7 7

© ankush agarwal 46
Histogram Matching (Specification)

(rk) (sk) G(zk) (zk) (rk) (zk)


0 1 0 0 0 0
1 3 0 1 1 1
2 5 0 2 2 2
3 6 1 3 3 3
4 6 2 4 4 4
5 7 5 5 5 5
6 7 6 6 6 6
7 7 7 7 7 7

© ankush agarwal 47
Histogram Matching (Specification)

(rk) (sk) G(zk) (zk) (rk) (zk)


0 1 0 0 0 0
1 3 0 1 1 1
2 5 0 2 2 2
3 6 1 3 3 3
4 6 2 4 4 4
5 7 5 5 5 5
6 7 6 6 6 6
7 7 7 7 7 7

© ankush agarwal 47
Histogram Matching (Specification)

(rk) (sk) G(zk) (zk) (rk) (zk)


0 1 0 0 0 0
1 3 0 1 1 1
2 5 0 2 2 2
3 6 1 3 3 3
4 6 2 4 4 4
5 7 5 5 5 5
6 7 6 6 6 6
7 7 7 7 7 7

© ankush agarwal 47
Histogram Matching (Specification)

(rk) (sk) G(zk) (zk) (rk) (zk)


0 1 0 0 0 0
1 3 0 1 1 1
2 5 0 2 2 2
3 6 1 3 3 3
4 6 2 4 4 4
5 7 5 5 5 5
6 7 6 6 6 6
7 7 7 7 7 7

© ankush agarwal 47
Histogram Matching (Specification)

(rk) (sk) G(zk) (zk) (rk) (zk)


0 1 0 0 0 0
1 3 0 1 1 1
2 5 0 2 2 2
3 6 1 3 3 3
4 6 2 4 4 4
5 7 5 5 5 5
6 7 6 6 6 6
7 7 7 7 7 7

© ankush agarwal 47
Histogram Matching (Specification)

(rk) (sk) G(zk) (zk) (rk) (zk)


0 1 0 0 0 0
1 3 0 1 1 1
2 5 0 2 2 2
3 6 1 3 3 3
4 6 2 4 4 4
5 7 5 5 5 5
6 7 6 6 6 6
7 7 7 7 7 7

© ankush agarwal 47
Histogram

• Question:
– What will be the effect on the histogram if we shuffle the pixels within the
image?

Answer:
• It’s histogram won’t change. No point processing will be affected
© ankush agarwal 48
Local Enhancement

• Histogram processing methods are global processing in the sense


that pixels are modified by a transformation function based on
the gray level content of an entire image
• Sometimes, we may need to enhance details over small areas in
an image, which is known as local enhancement

© ankush agarwal 49
SPATIAL FILTERING

© ankush agarwal 50
Spatial Filtering

• Enhancement techniques based on the neighbours of pixel of an


image are often referred to as Spatial filtering
• Filter term in “Digital image processing” is referred to the sub-
image
• Sub-image is also termed as mask, kernel, template, or window
• The value in a filter sub-image are referred as coefficients, rather
than pixels

© ankush agarwal 50
Spatial Filtering

Spatial filter Smoothing


Sharpening

Linear filter Non-linear filter

Average filter Order statistics

Weighted average Median filter

Derivative filter Min filter

Laplacian filter Max filter


© ankush agarwal 51
Mechanics of Spatial filtering

• The process consists simply of moving the filter mask from point
to point in an image
• At each point (x, y), the response of the filter at that point is
calculated using a predefined relationship

R  w1 z1  w2 z 2  ...  wmn z mn
mn
 w z
i i
i i

© ankush agarwal 52
Mechanics of Spatial filtering

Origin x

Original Image
Pixels

Image f (x, y)
y
© ankush agarwal 53
Mechanics of Spatial filtering

Origin x

e *
Original Image Filter
Pixels

Image f (x, y)
y
© ankush agarwal 53
Mechanics of Spatial filtering

Origin x

e *
Original Image Filter
Pixels
eprocessed = r*a + s*b + t*c +
u*d + v*e + w*f +
x*g + y*h + z*i
The above is repeated for every pixel in the
Image f (x, y) original image to generate the filtered image
y
© ankush agarwal 53
Smoothing Spatial Filters

• Used for blurring and for noise reduction

• Blurring is used in preprocessing steps, such as


– removal of small details from an image prior to object extraction
– bridging of small gaps in lines or curves

• Noise reduction can be accomplished by blurring with a linear


filter and also by a nonlinear filter
• There are 2 types of smoothing spatial filters
– Linear filters
– Order statistics filters
© ankush agarwal
Linear filters  Average filter

• The general implementation for filtering an M x N image with a


average/weighted average filter of size m x n is given by the
expression

© ankush agarwal 55
Linear filters  Average filter

• Output is simply the average of the pixels contained in the


neighbourhood of the filter mask
• Also called averaging filters or Lowpass filters and is useful for
highlighting gross detail
1 1 1

1 1 1 1
9
1 1 1

© ankush agarwal 56
Linear filters  Average filter (Results)

• Original image of 500 x 500 pixels


• Results of smoothing with averaging filter
masks of size m = 3, 5, 9, 15 and 35
• Note:
– big mask is used to eliminate small objects
from an image

© ankush agarwal 58
Linear filters  Weighted average filter

• More effective smoothing filters can be generated by allowing


different pixels in the neighbourhood having different weights in
the averaging function
• Pixels closer to the central pixel are more important
• Often referred to as a weighted averaging

1 2 1
1
2 4 2
16
1 2 1

© ankush agarwal 59
Non-linear filters  Order statistics filters

• Order-statistics filters are nonlinear spatial filters whose response


is based on ordering (ranking) the pixels contained in the image
area encompassed by the filter,
• Types:
– median filter : R = median{zk |k = 1, 2, …, n x n}
– max filter : R = max{zk |k = 1, 2, …, n x n}
– min filter : R = min{zk |k = 1, 2, …, n x n}

© ankush agarwal 60
Non-linear filters  Order statistics filters  Median
filter

• Sort the values of the pixel in the region


• In the M x N mask, the median is the middle element
• Eg:

Solution:
• 10, 15, 20, 20, 20, 20, 20, 25, 100

© ankush agarwal 61
Non-linear filters  Order statistics filters  Min filter

• Sort the values of the pixel in the region


• In the M x N mask, the min is the first element
• Eg:

Solution:
• 10, 15, 20, 20, 20, 20, 20, 25, 100

© ankush agarwal 62
Non-linear filters  Order statistics filters  Max filter

• Sort the values of the pixel in the region


• In the M x N mask, the max is the last element
• Eg:

Solution:
• 10, 15, 20, 20, 20, 20, 20, 25, 100

© ankush agarwal 63
Non-linear filters  Order statistics filters  Median
filter

• Median filtering is particularly effective in the presence of impulse


noise (salt and pepper noise)
• Unlike average filtering, median filtering does not blur too much
image details

• Advantages:
– Removes impulsive noise
– Preserves edges
• Disadvantages:
– performance poor when # of noise pixels in the window is greater than 1/2
# in the window
– performs poorly with Gaussian noise

© ankush agarwal 64
Non-linear filters  Order statistics filters  Median
filter

a) X-ray image of circuit board corrupted by salt-pepper noise


b) Noise reduction with a 3 x 3 averaging mask
c) Noise reduction with a 3 x 3 median filter
© ankush agarwal 65
Blurring v/s Sharpening

• As we know that blurring can be done in spatial domain by pixel


averaging in a neighbours
• Averaging is analogous to integration
• Therefore, logically it can be concluded that the sharpening must
be accomplished by spatial differentiation

© ankush agarwal 66
Sharpening Spatial Filters

• The principal objective of sharpening is to highlight fine detail in


an image or to enhance detail that has been blurred
• First and second order derivatives are commonly used for
sharpening
f
 f ( x  1)  f ( x)
x
2 f
 f ( x  1)  f ( x  1)  2 f ( x)
x 2

© ankush agarwal 67
Derivative operator

• Response of first order derivative is:


– zero in flat segments
– Non zero at the onset (beginning) of a ramp
– Non zero along ramps

• Response of second order derivative is:


– Zero in flat areas
– Non zero at the onset (beginning) of a ramp
– Zero along ramps of constant slope

© ankush agarwal 68
Derivative operator

• Eg:

5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 . . .

© ankush agarwal 69
Derivative operator

• First-order derivatives generally produce thicker edges in an


images
• Second-order derivatives have a stronger response to fine detail
(e.g. thin lines or isolated points).
• First-order derivatives generally have a stronger response to a
gray-level step
• Second-order derivatives produce a double response at step
changes in gray level

© ankush agarwal 70
Derivative operator  Laplacian (Second derivative)

• The filter is expected to be isotropic: response of the filter is


independent of the direction of discontinuities in an image
• The digital implementation of the 2-Dimensional Laplacian is
obtained by summing 2 components
0 1 0
 f  f
2 2
 f  2  2
2

x y 1 -4 1

0 1 0

© ankush agarwal 71
Derivative operator  Laplacian (Second derivative)

0 1 0 0 -1 0
1 -4 1 -1 4 -1  90° isotropic

0 1 0 0 -1 0

1 1 1 -1 -1 -1
45° isotropic  1 -8 1 -1 8 -1
1 1 1 -1 -1 -1
© ankush agarwal 72
Derivative operator  Laplacian (Second derivative)

• 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

© ankush agarwal 73
Derivative operator  Laplacian (Second derivative)

© ankush agarwal 74
RECAP

© ankush agarwal
Recap

Image Enhancement

Frequency
Spatial Domain
Domain

Intensity Transformation

Spatial Filtering

© ankush agarwal
Recap

• Linear transformations
– Image negative
• Non-linear transformations
– Logarithmic transformation
– Power Law (Exponential) transformation
• Piecewise-linear transformations
– Contrast stretching
– Gray-level slicing
– Bit plane slicing
• Histogram

© ankush agarwal
Recap

Spatial filter Smoothing


Sharpening

Linear filter Non-linear filter

Average filter Order statistics

Weighted average Median filter

Derivative filter Min filter

Laplacian filter Max filter


© ankush agarwal
GLA UNIVERSITY

DIGITAL IMAGE PROCESSING

By:
Dr. Ankush Agarwal
Outline

• Introduction and Fundamentals:


– Motivation and Perspective, Applications, Components of Image
Processing System,
– Element of Visual Perception, A Simple Image Model,
– Sampling and Quantization, Some Basic Relationships between Pixels
• Intensity Transformations and Spatial Filtering:
– Introduction, Some Basic Intensity Transformation Functions,
– Histogram Processing, Histogram Equalization, Histogram Specification,
– Local Enhancement, Enhancement using Arithmetic/Logic Operations
– Basics of Spatial Filtering, Smoothing, Sharpening
• Filtering in the Frequency Domain:
– Fourier Transform and the Frequency Domain,
– Basis of Filtering in Frequency Domain
© ankush agarwal 2
FOURIER TRANSFORM

© ankush agarwal 3
Fourier Transform

• Any function that periodically repeats itself


• It can be expressed as a sum of sines/cosines with different
amplitudes A, frequencies f, and phases p
y(x) = A sin(fx + p)
• This sum is called a Fourier Series

• Even functions that are not periodic (but whose area under the
curve is finite) can be expressed as the integral of sines and/or
cosines multiplied by a weighting function

© ankush agarwal 4
Fourier Transform

• We want to understand the frequency w of our signal. So, let’s


reparametrize the signal by w instead of x:

© ankush agarwal 5
Fourier Transform

• The Fourier transform of f(x) is:



F (u )  

f ( x) e  j 2 ux dx


 

f (x)[cos 2 ux  jsin 2 ux] dx

• The inverse Fourier transform of f(x) is:



f ( x)  

F (u ) e j 2 ux du

© ankush agarwal 6
Fourier Transform

• Eg:
– Find its Fourier Transform

© ankush agarwal 7
Fourier Transform

Solution

© ankush agarwal 8
Fourier Transform (Discrete)

• The Fourier transform of a discrete function of one variable, f(x), x


= 0, 1, …, M-1, is given by the following equation

For u = 0, 1, 2, …, M-1
Where j  1

• Inverse

© ankush agarwal 9
Fourier Transform (Discrete)

• Eg:
– Find the DFT of f(x) = {0, 1, 2, 1}

Euler’s Formula:

ejθ = cosθ + j sinθ

© ankush agarwal 10
Fourier Transform (Discrete)

 j 2  ux
M 1
F (u )   f ( x) e
x 0
M

Solution

F (0)   0  1  2  1
4

© ankush agarwal 11
Fourier Transform (Discrete)

Solution
 j 2  ux
3
F (u  1)   f ( x) e M

x 0
 j 2  1.0  j 2  1.1  j 2  1.2  j 2  1.3

 0.e 3
 1.e 3
 2.e 3
 1.e 3

 2

• Similarly, we can compute F(2) and F(3)

© ankush agarwal 12
Fourier Transform (Discrete)

Solution
F(0) = 4
F(1) = -2
F(2) = 0
F(3) = -2

© ankush agarwal 13
Fourier Transform (Discrete)

• Twiddle factor
– A new factor defined as

WM  e  j 2 / M
• Now M 1
F (u )  
x 0
f ( x) WMux

• The equation now reduces to


F = W.f
where WM is a primitive Mth root of unity
© ankush agarwal 14
Fourier Transform (Discrete)

• Eg:
– If M = 4, then WM will be a 4x4 matrix

© ankush agarwal 15
Fourier Transform (Discrete)

Solution  j 2  .0
WM0  e 4

1

 j 2 .1
WM1  e 4

   
 cos    j sin  
 2  2
j

© ankush agarwal 16
Fourier Transform (Discrete)

Solution

© ankush agarwal 17
Fourier Transform (Discrete)

Find the DFT of f(x) = {0, 1, 2, 1}

© ankush agarwal 18
Fourier Transform (Discrete)

• Eg:
– Find the DFT of the following f(x) = {1,1,0,0}

Solution
• F(u) = {2, 1-j, 0, 1+j}

© ankush agarwal 19
Fourier Transform (Discrete)

• Eg:
– Find the IDFT of the following F(u) = {1,0, 1, 0}

Solution
• f(x) = {0.5, 0, 0.5, 0}

© ankush agarwal 20
Fourier Transform (Discrete)

• Eg:
– Find the DFT of the following image.

0 1 2 1
1 2 3 2
2 3 4 3
1 2 3 2

© ankush agarwal 21
Low pass vs high pass filters

• Low pass filter are used for image smoothing in the frequency
domain
• It removes high frequency noise from the image and preserves
low frequency components

• High pass filter are used for image sharpening in the frequency
domain
• It removes low frequency noise from the image and preserves
high frequency components

© ankush agarwal 22
Ideal filter

• Low pass
1 D(u, v)  D 0
H (u, v)  
0 D(u, v)  D0
• High pass
0 D(u, v)  D 0
H (u, v)  
1 D(u, v)  D 0
• ILPF passes all the frequencies within a circle of radius D0 from
the origin without attenuation and cuts off all the frequencies
outside the circle
• Where,
– D0 is a positive constant
– D(u, v) is the Euclidean Distance from any point (u, v) to the origin
© ankush agarwal 23
Butterworth filter

• It can be expressed as
1
H (u, v) 
1  [ D(u, v) / D 0 ]2 n

© ankush agarwal 24
Gaussian filter

• Low pass
D 2 (u,v)/2 2
H (u, v)  e
• High Pass

 D 2 (u,v)/2 D0 2
H (u, v)  1  e

© ankush agarwal 25
RECAP

© ankush agarwal 26
Recap

• Fourier and Inverse fourier (continuous)


• Fourier (discrete) M 1
 j 2  ux

F (u )  M
 f ( x) e
x 0

• Inverse fourier (discrete) M 1


j 2  ux
1
f ( x) 
M
 F (u ) e
u 0
M

• Fourier 1D, 2D
M 1
• Twiddle factor
WM  e  j 2 / M F (u )   f ( x) W
x 0
ux
M

• Low pass and high pass filters


– Ideal, Butterworth, Gaussian

© ankush agarwal 27
GLA UNIVERSITY

DIGITAL IMAGE PROCESSING

By:
Dr. Ankush Agarwal
Outline

• Morphological Image Processing


– Introduction, Logical Operations involving Binary Images,
– Dilation and Erosion, Opening and Closing, The Hit-or-Miss Transformation,
– Morphological Algorithms – Boundary Extraction, Region Filling, Extraction of
Connected Components, Convex Hull, Thinning, Thickening
• Image Segmentation
– Point, Line & Edge detection, Thresholding, Region-based Segmentation,
– Region Extraction - Pixel Based Approach & Region Based Approach,
– Edge and Line Detection - Basic Edge Detection, Canny Edge Detection,
– Edge Linking - Hough Transform.
• Representation & Description
– Representation - Boundary Following, Chain Codes,
– Boundary Descriptors - Shape Numbers

© ankush agarwal 2
MORPHOLOGY

© ankush agarwal 3
Morphology

• Mathematical tool for processing shapes in binary images,


including boundaries, skeletons, convex hulls, etc
• Morphological operations are used to remove the imperfections
introduced during segmentation

© ankush agarwal 4
Morphology

• Mathematical tool for processing shapes in binary images,


including boundaries, skeletons, convex hulls, etc
• Morphological operations are used to remove the imperfections
introduced during segmentation

© ankush agarwal 4
Set Theory

• Set (Ω): A collection of objects (elements)


• Membership (): If  is an element of a set Ω, we can write  

• Subset (): Let A and B are two sets, if for every a  A, we also
have a  B,then the set A is a subset of B,then, A  B
– If A  B and B  A, then A = B
• Empty set (): empty set
• Complement: If A  , then its complement set Ac = {|  
, and  A}

© ankush agarwal 5
Set Theory

• Union (): A  B = {|   A or B}


• Intersection (): A  B = {|   A and B}
• Set difference (-): B\A = B  Ac
– Note that B-A  A-B
• Disjoint sets: A and B are disjoint (mutually exclusive) if
A  B= 

© ankush agarwal 6
Example sets operations

© ankush agarwal 7
Reflection and Translation

• Reflection
– The reflection of a set B, denoted by 𝐵, is defined as
𝐵 = 𝑤|𝑤 = −𝑏, 𝑓𝑜𝑟 𝑏𝐵
• Translation
– The translation of a set B by point z = (z1, z2), denoted by (B)z is defined as
𝐵 𝑧 = 𝑐|𝑐 = 𝑏 + 𝑧, 𝑓𝑜𝑟 𝑏𝐵

© ankush agarwal 8
Reflection and Translation

• Eg:

© ankush agarwal 9
Binary Image

• Binary image
– bi-valued function of x and y
• Morphological theory views
– binary image as a set of its foreground (1-valued) pixels

© ankush agarwal 10
Basic components in Morphology

• Every operation has two elements


– Input Image
– Structuring element
• The results of the operation mainly depends upon the structuring
element chosen

© ankush agarwal 12
Structuring Elements

• Small sets or sub-images used to analyze an image for properties


of interest
• Structuring elements can be any size and any shape

© ankush agarwal 13
Fundamental Operations

• Fundamentally, morphological image processing is like spatial


filtering
• The structuring element is moved across every pixel in the
original image to give a new value of a pixel in processed image
• The value of this pixel depends on the operation performed
• There are two basic morphological operations
– Dilation
– Erosion

© ankush agarwal 14
DILATION AND EROSION

© ankush agarwal 15
Dilation

• Dilation is an operation that grows or thickens objects in a binary


image
• The specific manner of this thickening is controlled by a shape
referred to as a structuring element
• The structuring element is translated throughout the domain of
the image to see where it overlaps with 1-valued pixels
• The output image is 1 at each location of the origin such that the
structuring element overlaps at least one 1-valued pixel in the
input image

© ankush agarwal 16
Dilation

• The dilation of an image I with structure element S is given by


I  S  {z | ( Sˆ ) z I  }

• Theoretical way of generation:


– Obtain the reflection of S about its origin
– Shift this reflection by z
– Dilation of I by S is the set of all structuring element origin locations
where the reflected and translated S overlaps at least some portion of I

© ankush agarwal 17
Dilation

• Eg:

© ankush agarwal 18
Dilation

• Eg:

© ankush agarwal 19
Dilation

• Eg:

© ankush agarwal 19
Dilation

• Eg:

© ankush agarwal 19
Dilation

• Eg:

© ankush agarwal 19
Dilation

• Eg:

© ankush agarwal 20
Applications

• Dilation can repair breaks

• Dilation can repair intrusions

© ankush agarwal 21
Properties of Dilation

• Dilation is commutative

• Dilation is associative

• Dilation is invariant to translation

© ankush agarwal 22
Erosion

• The erosion of an image I with structure element S is given by

I S = {z |(S)z  I
– The set of all points z such that, S translated by z, is contained by I

𝐼 𝑆 = 𝑧| 𝑆 𝑍 ∩ 𝐼𝑐 = ∅
• In other words, erosion of I by S is the set of all structuring
element origin locations where the translated S has no overlap
with the background of I

• Erosion “shrinks” or “thins” objects in a binary image

© ankush agarwal 23
Erosion

• Eg:

© ankush agarwal 24
Erosion

• Eg:

© ankush agarwal 24
Erosion

• Eg:

© ankush agarwal 24
Erosion

• Eg:

© ankush agarwal 25
Application

• Erosion can split apart joined objects

• Erosion shrinks objects and removes random outer edges

© ankush agarwal 26
Concept

• Binary image
0 1 2 3 4 5 6 7 -1 0 1
0 x  Image (I)
-1
Structure Element (S) 
1 0 X
2 1
3
I = {(2,2), (3,2), (3,3), (4,3), (4,4), (5,4)}
4
U = {(0,0), ..., (7,7)}
5
S = {(-1,-1), (0,-1)}
6
7
© ankush agarwal 27
Concept

• Reflection and Translation operations

x x x

I = {(1,1), (1,2)} Iˆ = {(-1,-1), (-1,-2)} I ( 1,1)  {(0, 0), (0,1)}

© ankush agarwal 28
Dilation (by coordinate system)

• Eg:
x x
X

S = {(-1,-1), (0,-1)}

I = {(2,2), (3,2), (3,3), (4,3), (4,4), (5,4)} (1,1), (2,1), (2, 2), (3, 2), (3,3), (4,3) 
I S  
(2,1), (3,1), (3, 2), (4, 2), (4,3), (5,3) 
I  S  {p | p  i  s,i  I,s  S}
 (1,1), (2,1), (2, 2), (3,1), (3, 2), (3,3), (4, 2), (4,3), (5,3)
© ankush agarwal 29
Dilation (general definition)

• Eg
x x

S = {(-1,-1), (0,-1)}

I S = {(1,1), (0,1)} ˆ
I  S  {p | [(S) p I]  }
ˆ
 {p | [(S) I]  I}
p
© ankush agarwal 30
Dilation (as Union of object translation)

• Eg
x x x
X

I I(-1,-1) I(0,-1)
I S  sS Is
© ankush agarwal 31
Dilation (as Union of object translation)

• Eg
x x

I
I S  sS Is
© ankush agarwal 31
Erosion (by coordinate system)

• Eg:
x x
X

S = {(-1,-1), (0,-1)}

I = {(2,2), (3,2), (3,3), (4,3), (4,4), (5,4)} (3,3)  {(1, 1), (0, 1)}  {(2, 2), (3, 2)}  I
(4, 4)  {(1, 1), (0, 1)}  {(3,3), (4,3)}  I
I S  {p | p  s  I,s  S}
(5,5)  {(1, 1), (0, 1)}  {(4, 4), (5, 4)}  I
© ankush agarwal 32
Erosion (general definition)

• Eg
x x

S = {(-1,-1), (0,-1)}

I S  {p | (S) p I c  }
 {p | [(S) p ]  I}

I
(3,3), (4, 4), (5,5)

© ankush agarwal 33
Erosion (as Intersection of object translation)

• Eg
x x

I I(1,1)
I S  sS Is
© ankush agarwal 34
Erosion (as Intersection of object translation)

• Eg
x x x
X

I I(1,1) I(0,1)
I S  sS Is
© ankush agarwal 34
Erosion (as Intersection of object translation)

• Eg
x x

I
I S  sS Is
© ankush agarwal 34
Eg:

• Find I  S
x
X

© ankush agarwal 35
Eg:

• Find I S
x
X

© ankush agarwal 36
Eg:

• Find I  S
x
X

© ankush agarwal 37
Eg:

• Find I  S
x
X

© ankush agarwal 38
Eg:

• Find I S
x
X

© ankush agarwal 39
Eg:

• Find I S
x

© ankush agarwal 40
Duality

• Erosion and dilation are duals of each other with respect to set
complementation and reflection
 A  B   z |  B  Z  A
c c

  z |  B  Z  A  
c c

  z |  B  Z  Ac  

 Ac  B

© ankush agarwal 41
Combining Dilation and Erosion

• Dilation and Erosion are not inverse transformations


• If an image is eroded & then dilated (or vice-versa), the original
image can not be obtained
• In practical applications, dilation and erosion are used most often
in various combinations
• Three of the most common combinations of dilation and erosion
are
– Opening
– Closing
– Hit or miss transformation

© ankush agarwal 42
OPENING AND CLOSING

© ankush agarwal 43
Opening and Closing

• Opening is erosion followed by dilation


• The opening is given as
A B  ( AB )  B
• Closing is dilation followed by erosion
• The closing is given as
A B  ( A  B )B

© ankush agarwal 44
Opening and Closing

• Opening
– smooth the contours of an object
– breaks narrow strips
– eliminates thin edges
– it is less destructive than the Erosion

• Closing
– smooth sections of the contours
– fuses narrow breaks & long thin gulfs
– eliminates small holes & fills gaps in the contour

© ankush agarwal 45
Closing

I
© ankush agarwal 46
Closing

I S
© ankush agarwal 46
Closing

I S  (I S )S
© ankush agarwal 46
Opening

I
© ankush agarwal 47
Opening

I S
© ankush agarwal 47
Opening

I S  (I S )  S
© ankush agarwal 47
HIT OR MISS TRANSFORM

© ankush agarwal 48
Hit or Miss Transform

• A basic tool for shape detection


• It is a morphological operator for finding local patterns of pixels
• The hit-or-miss transform is a general binary morphological
operation that can be used to look for particular patterns of
foreground and background pixels in an image

• Concept:
– Hit object
– Miss background

© ankush agarwal 49
Hit or Miss Transform

• It is given as
I ⊛ S  ( I S ) ( I c (W  S ))
• It can be written as
I ⊛ S  ( I S1 ) ( I c S 2 )
– where,
• S1 is the set formed from elements of S associated with an object (S in this case)
• S2 is the set of elements of S associated with the corresponding background (W –
S)
• The set contains all the points at which, S1 found a match (hit) in
I and S2 found a match in Ic

© ankush agarwal 50
Hit or Miss Transform

• Using the definition of set difference & the dual relationship


between erosion & dilation, the equation can be rewritten as
I ⊛S  ( I S1 )  ( I  Sˆ2 )

© ankush agarwal 51
Hit or Miss Transform

© ankush agarwal 52
Hit or Miss Transform

I S

© ankush agarwal 52
Hit or Miss Transform

Ic x

W-S
© ankush agarwal 53
Hit or Miss Transform

I c (W  S) x

W-S
© ankush agarwal 53
Hit or Miss Transform

I ⊛ S  ( I S ) ( I c (W  S ))

© ankush agarwal 54
Eg

• Find I ⊛ S
0 0 0 0 0 0 0 0 0 0 I x 1 x
0 1 1 1 1 1 1 1 0 0 S 0 1 1
0 1 1 1 1 1 1 1 0 0 0 0 x
0 1 1 1 1 1 1 1 0 0
0 1 1 1 1 1 1 0 0 0
0 1 1 1 1 1 0 0 0 0
0 1 1 1 1 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

© ankush agarwal 55
Eg:

0 0 0 0 0 0 0 0 0 0 x 1 x
0 0 0 0 0 0 0 0 0 0 0 1 1
0 1 1 1 1 1 1 0 0 0 0 0 x
0 1 1 1 1 1 1 0 0 0 S
0 1 1 1 1 1 0 0 0 0
0 1 1 1 1 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

I S
© ankush agarwal 56
Eg:

1 1 1 1 1 1 1 1 1 1 x 1 x x 0 x
1 0 0 0 0 0 0 0 1 1 0 1 1 1 0 0
1 0 0 0 0 0 0 0 1 1 0 0 x 1 1 x
1 0 0 0 0 0 0 0 1 1 S W-S
1 0 0 0 0 0 0 1 1 1
1 0 0 0 0 0 1 1 1 1
1 0 0 0 0 1 1 1 1 1
1 0 0 0 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1

Ic
© ankush agarwal 57
Eg:

0 0 0 0 0 0 0 0 0 1 x 1 x x 0 x
0 0 0 0 0 0 0 0 0 1 0 1 1 1 0 0
0 0 0 0 0 0 0 0 0 1 0 0 x 1 1 x
0 0 0 0 0 0 0 0 0 1 S W-S
0 0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 1 1 1 1
0 1 0 0 0 1 1 1 1 1
0 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0

I c (W  S)
© ankush agarwal 57
Eg:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1
0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1
0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1
0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1
0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

© ankush agarwal 58
Eg:

0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

© ankush agarwal 58
Eg

• Find I ⊛ S

0 0 0 0 0 0 0 0 0 0 0 0 I 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0 0 0 S 0 1 1 1 0
0 1 1 1 0 0 0 0 1 1 1 0 0 1 1 1 0
0 1 1 1 0 0 0 0 1 1 1 0 0 1 1 1 0
0 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0

© ankush agarwal 59
Eg

• Find I ⊛ S

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

I S I c (W  S)

© ankush agarwal 60
BOUNDARY EXTRACTION

© ankush agarwal
Boundary Extraction

• The boundary of an object in an image is the set of pixels that


have one or more neighbours
• A boundary is a contour in the image that represents a change in
pixel ownership from one object to another
• There are two types of boundary
– Internal boundary: It contains boundary pixels that are inside the object
 ( I )  I  ( I S )
– External boundary: It contains boundary pixels that are outside the object
 (I )  (I  S )  I

© ankush agarwal 62
Boundary Extraction

• Eg:
– Find  ( I ) (internal boundary)

1 1 1 0 1 1 1 1 1 0 I 1 1 1
1 1 1 0 1 1 1 1 1 0 S 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1

© ankush agarwal 63
Boundary Extraction

1 1 1 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0
1 1 1 0 1 1 1 1 1 0 0 1 0 0 0 1 1 1 0 0
1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 1 1 1 0 0
1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0

I S

© ankush agarwal 64
Boundary Extraction

1 1 1 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0
1 0 1 0 1 0 0 0 1 0 0 1 0 0 0 1 1 1 0 0
1 0 1 1 1 0 0 0 1 1 0 1 0 0 0 1 1 1 0 0
1 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
I  ( I S ) I S

© ankush agarwal 64
Boundary Extraction

• Eg:
– Find  ( I ) (internal and external boundary)

I
x

x
S

© ankush agarwal 65
Boundary Extraction

x x

I S
© ankush agarwal 66
Boundary Extraction

x x

I  ( I S ) I S
© ankush agarwal 66
Boundary Extraction

x x

I S
© ankush agarwal 67
Boundary Extraction

x x

(I  S )  I I S
© ankush agarwal 67
REGION FILLING

© ankush agarwal 68
Region Filling

• Region filling is used to fill the selected region of the object


• Steps includes
– Choose a seed point X0
– Iterate X k  ( X k 1  S ) I c until convergence

© ankush agarwal 69
Region Filling

x
I
S x

© ankush agarwal 70
Region Filling

654 3
43 2 3
2 1 2
1 0 1
2 1 2

© ankush agarwal 71
Region Filling

• Eg:
x
I
S x

© ankush agarwal 72
Region Filling

• Eg: x

I
S x

© ankush agarwal 73
EXTRACTION OF CONNECTED COMPONENTS

© ankush agarwal 74
Extraction of Connected Components

• Connected component labeling is used in computer vision to


detect connected regions in the images
• It groups the pixels into components based on the pixel
connectivity
• Steps includes
– Choose a seed point X0
– Iterate X k  ( X k 1  S ) I until convergence

© ankush agarwal 75
Extraction of Connected Components

x
I
S x

© ankush agarwal 76
Extraction of Connected Components

© ankush agarwal 77
Extraction of Connected Components

• Eg: x
I
S x

© ankush agarwal 78
CONVEX HULL

© ankush agarwal 79
Convex Hull

• A set I is said to be convex if the straight line segment joining any


two points in I lies entirely within I

© ankush agarwal 80
Convex Hull

• Convex Hull (H) = Minimum convex set containing set I


• Hull Deficiency (D) = H – I

• Steps include
– Choose a seed point X0
– do i = 0 to 3
• Iterate X k  ( X k 1 ⊛ Si ) I until convergence
– Minimize convex set using bounding box of I

© ankush agarwal 81
Convex Hull

I
x 1 x x 1 1 1

S 1 0 x x 0 x

1 x x x x x

S0 S1
x x 1 x x x

x 0 1 x 0 x

x x 1 1 1 1

S2 S3

© ankush agarwal 82
Convex Hull

x 1 x x

1 0 x

1 x x
0 1
0 1 2 S0
1 2
0

© ankush agarwal 83
Convex Hull

x 1 1 1

x 0 x

x x x
0 1
0 1 2 S1
1 2
0
3
3 4
4 5
6

© ankush agarwal 83
Convex Hull

0 1
0 1 2
1 2
x x 1
7 0
x 0 1
8 3
7 3 4 x x 1

4
6
5
S2

© ankush agarwal 83
Convex Hull

0 1
0 1 2
1 2
x x x
7 0
x 0 x
8 3
7 3 4 1 1 1

S3
4 5
6

© ankush agarwal 83
Convex Hull

0 1
0 1 2
1 2
7 0
8 3
7 3 4
4 5
6

© ankush agarwal 84
Convex Hull

x x

0 1
0 1 2
1 2
7 0
8 3
7 3 4
4 5
6

© ankush agarwal 84
Convex Hull

x x

0 1
0 1 2
1 2
7 0
8 3
7 3 4
4 5
6

© ankush agarwal 84
Convex Hull

x x

0 1
0 1
1
0
3
7 3 4
4 5

© ankush agarwal 84
Convex Hull

x x

© ankush agarwal 84
Convex Hull

x x

H
0 1 I
0 1
1
0
3
7 3 4
4 5

© ankush agarwal 85
Convex Hull

x x

0 1
0 1
1
0 D
3
7 3 4
4 5

© ankush agarwal 85
MORPHOLOGICAL THINNING AND THICKENING

© ankush agarwal 86
Thinning

• It is an operation that is used to remove selected foreground


pixels from binary images
• It is the process of reducing an object in a digital image to the
minimum size
• It is given by
I  S  I  ( I ⊛ Si )
I S  I ( I ⊛ Si )
I  {S }  (((( I ⊛ S0 ) ⊛ S1 ) ⊛ S 2 ) ...⊛S7 )

© ankush agarwal 87
Thinning

• Thinning is basically a search & delete process


• It removes only those boundary pixels from the image whose
deletion
– Does not break connectivity of their neighbours locally
– Does not reduce the length of the already thinned curve

• Critical pixel
– Its deletion changes the connectivity of its neighbourhood locally

• End pixel
– Its deletion reduces the length of an already thinned curve
© ankush agarwal 88
Thinning
0 0 0 X 0 0 1 X 0

X 1 X 1 1 0 1 1 0

1 1 1 1 1 X 1 X 0

S0 S1 S2
1 1 X 1 1 1 X 1 1

1 1 0 X 1 X 0 1 1

X 0 0 0 0 0 0 0 X

S3 S4 S5
0 X 1 0 0 X

I 0 1 1 0 1 1

0 X 1 X 1 1

S6 S7
© ankush agarwal 89
Thinning
0 0 0

X 1 X

1 1 1

0 0 0 0 0 0 0
S0

© ankush agarwal 90
Thinning
X 0 0

1 1 0

1 1 X

0 0 0 0 0 0 0
S1

© ankush agarwal 90
Thinning
1 X 0

1 1 0

1 X 0

0 0 0 0 0 0 0
S2

0
0

© ankush agarwal 90
Thinning

0 0 0 0 0 0 0
1 1 X

1 1 0
0 X 0 0

0
S3
0

© ankush agarwal 90
Thinning

0 0 0 0 0 0 0
1 1 1

X 1 X
0 0 0 0

0 0
S4
0 0 0 0

© ankush agarwal 90
Thinning

0 0 0 0 0 0 0
X 1 1

0 1 1
0 0 0 X

0 0 0
S5
0 0 0 0

© ankush agarwal 90
Thinning

0 0 0 0 0 0 0

0 0
0 0 0
0 0 0 0 0 X 1

0 1 1

0 X 1

S6
© ankush agarwal 90
Thinning

0 0 0 0 0 0 0

0 0
0 0 0
0 0 0 0 0 0 X

0 1 1

X 1 1

S7
© ankush agarwal 90
Thinning

© ankush agarwal 91
Thinning
0 0 0

X 1 X

1 1 1

S0
0 0 0 0 0

© ankush agarwal 91
Thinning
X 0 0

1 1 0

1 1 X

S1
0 0 0 0 0

© ankush agarwal 91
Thinning
1 X 0

1 1 0

1 X 0

S2
0 0 0 0 0

© ankush agarwal 91
Thinning

1 1 X
0 0 0 0 0
1 1 0

X 0 0

S3

© ankush agarwal 91
Thinning

1 1 1
0 0 0 0 0
X 1 X

0 0 0

0 0
S4

© ankush agarwal 91
Thinning

X 1 1
0 0 0 0 0
0 1 1

0 0 X

0 0 0
S5

© ankush agarwal 91
Thinning

0 0 0 0 0

0 0 0

0 X 1

0 1 1

0 X 1

S6
© ankush agarwal 91
Thinning

0 0 0 0 0

0 0 0

0 0 X

0 1 1

X 1 1

S7
© ankush agarwal 91
Thinning

© ankush agarwal 92
Thinning

© ankush agarwal 92
Thinning

• Eg:

© ankush agarwal 93
Thickening

• Thickening is the morphological dual of thinning


• It is defined as
I SI (I ⊛ Si )

I {S }  (((( I ⊛ S0 ) ⊛ S1 ) ⊛S
2 ) ...⊛S 7 )

• Approach
– Take Ic
– res = Apply thinning on Ic
– Take resc
I {S } | ( I c  S ) followed by (isolated pixel removal) |c
© ankush agarwal 94
RECAP

• Dilation I  S  {z | ( Sˆ ) z I  }
• Erosion I S  {z | ( S ) z I c  }

• Opening I S  ( I S )  S

• Closing I S  ( I  S )S

• Hit or Miss I ⊛S  ( I S ) ( I c (W  S ))

• Boundary (Internal)  ( I )  I  ( I S )
• Boundary (External)  (I )  (I  S )  I
© ankush agarwal 95
RECAP

• Region Filling X k  ( X k 1  S ) Ic

• Connected Components X k  ( X k 1  S ) I

• Convex Hull X k  ( X k 1 ⊛ Si ) I

• Thinning I  {S }  (((( I ⊛ S 0 ) ⊛ S1 ) ⊛S 2 ) ...⊛S7 )

• Thickening I {S }  | ( I c  S ) isolated pixel removal |c

© ankush agarwal 96
GLA UNIVERSITY

DIGITAL IMAGE PROCESSING

By:
Dr. Ankush Agarwal
Outline

• Morphological Image Processing


– Introduction, Logical Operations involving Binary Images,
– Dilation and Erosion, Opening and Closing, The Hit-or-Miss Transformation,
– Morphological Algorithms – Boundary Extraction, Region Filling, Extraction of
Connected Components, Convex Hull, Thinning, Thickening
• Image Segmentation
– Point, Line & Edge detection, Thresholding, Region-based Segmentation,
– Region Extraction - Pixel Based Approach & Region Based Approach,
– Edge and Line Detection - Basic Edge Detection, Canny Edge Detection,
– Edge Linking - Hough Transform
• Representation & Description
– Representation - Boundary Following, Chain Codes,
– Boundary Descriptors - Shape Numbers

© ankush agarwal 2
SEGMENTATION

© ankush agarwal 3
Segmentation

• Image segmentation is a technique to extract the attributes of the


image
• Segmentation attempts to partition the pixels of an image into
groups that strongly correlate with the objects in an image
• Mostly used in computer vision application

Image Segmentation Attributes

© ankush agarwal 4
Segmentation

• Separate image into coherent objects

© ankush agarwal 5
Segmentation

• The purpose of image segmentation is to partition an image into


meaningful regions with respect to a particular application
• The segmentation is based on various factors that are taken from
the image, which includes
– Intensity, Color, Texture, Depth, Shape, Size, Association, etc

© ankush agarwal 6
Segmentation

• Segmentation algorithms are based on 2 properties of intensity


values
Segmentation

Discontinuity Similarity

• Discontinuity: pixel, line, edges


• Similarity: region growing, split

© ankush agarwal 7
Segmentation

• Let v be the spatial domain on which the image is defined


• Image segmentation divides v into n regions Ri (i = 1 to n), such
that n
i 1 Ri  v
Ri Rj  

© ankush agarwal 8
Segmentation (Basic Idea)

• All the image segmentation methods assume that


– the intensity values are different in different regions
– within each region of the corresponding object, the intensity values are
similar

• For this, we need to apply threshold

© ankush agarwal 9
Thresholding

• Gray level thresholding is the simplest segmentation process


• Thresholding is computationally inexpensive and fast
• Thresholding as a transformation function
T = T[x, y, p(x, y), f(x, y)]
– where
– f(x, y) is the gray level of the point (x, y)
– p(x, y) denotes some local property (average of a pixels centred at (x, y))

© ankush agarwal 10
Thresholding (Types)

• Global Thresholding
– If T is the only function of f(x, y), then the threshold is called global
threshold
– Apply the same threshold to the whole image

• Local Thresholding
– If T is a function of both f(x, y) & p(x, y), then the threshold is called local
– The threshold depends on local property

• Dynamic (Adaptive) Thresholding


– The threshold depends on spatial coordinates (x, y)

© ankush agarwal 11
Thresholding

• Thresholding is the transformation of an input image f to an


output (segmented) binary image g
1 if f (x, y)  T
g (x, y)  
0 otherwise
– where, T is threshold

© ankush agarwal 12
Thresholding

• Eg:
– Disk = 255 and background = 127
– Segment the image into two regions: disk and background
– What will be the threshold values?

© ankush agarwal 13
Global Thresholding

• Based on the histogram of an image


• Partition the image histogram using a single global threshold
• The success of this technique strongly depends on how well the
histogram can be partitioned

© ankush agarwal 14
Global Thresholding (Algorithm)

• Select an initial estimate for T (typically the average)


• Segment the image using T to produce two groups of pixels:
– G1 consisting of pixels with grey levels >T
– G2 consisting pixels with grey levels ≤ T
• Compute the average grey levels of pixels in G1 to give μ1 and G2
to give μ2
• Compute a new threshold value T = (μ1+ μ2)/2

• Repeat steps 2–4 until the difference in T in successive iterations


is less than a predefined limit

© ankush agarwal 15
Global Thresholding (Problem)

• Single value thresholding only works for bimodal histograms (two


peaks)
• Images with other kinds of histograms need more than one
threshold

© ankush agarwal 16
Global Thresholding (Problem)

© ankush agarwal 17
Global Thresholding (Problem)

© ankush agarwal 18
Adaptive Thresholding

• The threshold for each pixel depends on its location within an


image, this technique is said to adaptive

© ankush agarwal 19
SEGMENTATION (SIMILARITY)

© ankush agarwal 20
Region

• A group of connected pixels with similar properties


• For correct interpretation, image must be partitioned into regions
that correspond to objects or parts of an object

© ankush agarwal 21
Region based approach

• Let R represent the entire image region


• Segmentation R into n sub regions, R1, R2, ..., Rn, such that
n
i 1 Ri  R
Ri is a connected region, i  1, 2,..., n
Ri R j   , for all i and j , i  j

© ankush agarwal 22
Region based approach

• The fundamental drawback of histogram based region detection is


that histograms provide no spatial information
• Region growing approaches exploit the important fact that pixels
which are close together have similar gray values

© ankush agarwal 23
Region growing

• Choose the seed pixels (1 for every segment)


• Check the neighboring pixels and add them to the region if they
are similar to the seed
• Repeat previous step for each of the newly added pixels, stop if no
more pixels can be added
1 1 9 9 9
1 1 9 9 9
5 1 9 9 9
5 5 5 3 9
3 3 3 3 3

© ankush agarwal 24
Region splitting

• Split starts from the assumption that the entire image is


homogeneous
• If this is not true (by the homogeneity criterion), then split image
into four sub images
• This splitting procedure is repeated recursively until we split the
image into homogeneous regions
I1 I2
I1 I2
I I41 I42
I3 I4 I3
I43 I44
© ankush agarwal 25
Region splitting

• If an image of dimensions N x N, that is in the powers of 2 (N =


2n):
– All regions produced by the splitting algorithm are squares having
dimensions M x M, where M is a power of 2 as well (M = 2m, M<= n)
– Since the procedure is recursive, it produces an image that can be
described by a tree, in which each nodes have four child (except leaf
node)
– Such a tree is called a Quadtree

© ankush agarwal 26
Region splitting

R
I1 I2

I41 I42 I1 I2 I3 I4
I3
I43 I44
I41 I41 I41 I41

© ankush agarwal 27
Region splitting

• Advantage
– Created regions are adjacent and homogenous
• Disadvantage
– Over splitting, since no merge is performed
– More clusters

• Improvement
– Split and Merge

© ankush agarwal 28
Region splitting and merging

• After splitting
• Merging phase
– If 2 adjacent regions are homogenous, they are merged
• Repeat merging step, until no further merging is possible

© ankush agarwal 29
SEGMENTATION (DISCONTINUITY)

© ankush agarwal 30
Segmentation (Discontinuity)

• There are basic three types of grey level discontinuities


– Points
– Lines
– Edges

• We typically find discontinuities using masks and correlation


• Discrete form of derivative is used

© ankush agarwal 31
Segmentation (Discontinuity)

• The filter is expected to be isotropic


– response of the filter is independent of the direction of discontinuities in
an image
• The digital implementation of the 2-Dimensional Laplacian is
obtained by summing 2 components
0 1 0
 f  f2 2
 f  2  2
2
1 -4 1
x y
0 1 0

© ankush agarwal 32
Segmentation (Discontinuity)

0 1 0 0 -1 0
1 -4 1 -1 4 -1  90° isotropic

0 1 0 0 -1 0

1 1 1 -1 -1 -1
45° isotropic  1 -8 1 -1 8 -1
1 1 1 -1 -1 -1
© ankush agarwal 33
Segmentation (DiscontinuityPoint)

• A point has been detected at the location on the mask center if


|R| >= T
– where
– T is a nonnegative threshold
– R is the sum of products of the coefficients with the gray levels contained
in the region encompassed by the mark

© ankush agarwal 34
Segmentation (Discontinuity  Point)

7 7 7 7 7 7 7 -1 -1 -1

7 10 7 7 7 7 7 -1 8 -1 24 -3
3 0 0 0

7 7 7 7 7 7 7 -1 -1 -1 -3
3 -3
3 0 0 0

7 7 7 7 7 7 7 P 0 0 3 3 3

7 7 7 7 4 7 7 0 0 3 24
-24 3

7 7 7 7 7 7 7 0 0 3 3 3

7 7 7 7 7 7 7

I Rp =I º|IPº P|

© ankush agarwal 35
Segmentation (Discontinuity  Line)

• The next level of complexity is to detect lines


• The masks below will extract lines that are one pixel thick and
running in a particular direction

-1 -1 -1 -1 -1 2 -1 2 -1 2 -1 -1
2 2 2 -1 2 -1 -1 2 -1 -1 2 -1
-1 -1 -1 2 -1 -1 -1 2 -1 -1 -1 2

© ankush agarwal 36
Segmentation (Discontinuity  Line)

1 1 1 1 1 1 1 1 -1 -1 -1
1 1 1 1 1 1 1 3 2 2 2 0 0 0 0 2 2
1 1 1 1 1 1 3 1 -1 -1 -1 0 0 0 2 2 0
1 1 1 1 1 3 1 1 H 6 6 6 0 0 2
3 3 3 3 3 1 1 1 12 12 12 6 2 2
1 1 1 1 1 1 1 1 6 6 6 4 2 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1
I |I º H|

© ankush agarwal 37
Segmentation (Discontinuity  Line)

1 1 1 1 1 1 1 1 -1 -1 2
1 1 1 1 1 1 1 3 -1 2 -1 0 0 0 0 2 4
1 1 1 1 1 1 3 1 2 -1 -1 0 0 0 2 4 12
1 1 1 1 1 3 1 1 D45º 0 0 0 0 12 4
3 3 3 3 3 1 1 1 0 0 0 6 4 2
1 1 1 1 1 1 1 1 0 0 0 4 2 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1
I |I º D45º|

© ankush agarwal 38
Segmentation (Discontinuity  Line)

1 1 1 1 1 1 1 1 -1 2 -1
1 1 1 1 1 1 1 3 -1 2 -1 0 0 0 0 2 2
1 1 1 1 1 1 3 1 -1 2 -1 0 0 0 2 2 0
1 1 1 1 1 3 1 1 V 0 0 0 0 0 2
3 3 3 3 3 1 1 1 0 0 0 0 2 2
1 1 1 1 1 1 1 1 0 0 0 2 2 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1
I |I º V|

© ankush agarwal 39
Segmentation (Discontinuity  Line)

1 1 1 1 1 1 1 1 2 -1 -1
1 1 1 1 1 1 1 3 -1 2 -1 0 0 0 0 4 4
1 1 1 1 1 1 3 1 -1 -1 2 0 0 0 4 4 0
1 1 1 1 1 3 1 1 D-45º 0 0 0 6 0 4
3 3 3 3 3 1 1 1 0 0 0 0 4 4
1 1 1 1 1 1 1 1 0 0 0 2 4 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1
I |I º D-45º|

© ankush agarwal 40
Segmentation (Discontinuity  Line)

1 1 1 1 1 1 1 1
1 10 10 10 10 14 14 3
1 10 10 10 14 14 12
3 1
1 16 16 16 16 12
3 14 1
3 12
3 12
3 12
3 36 14 14 1
1 16 16 16 14 14 10 1
1 10 10 10 10 10 10 1
1 1 1 1 1 1 1 1

© ankush agarwal 41
Segmentation (Discontinuity  Edge)

• Edges characterize boundaries


• Edges in images are areas with strong intensity contrasts – a
jump in intensity from one pixel to the next
• Edge detecting in an image significantly reduces the amount of
data and filters out useless information, while preserving the
important structural properties in an image

© ankush agarwal 42
Segmentation (Discontinuity  Edge)

• Edge linking
– process takes an unordered set of edge pixels produced by an edge
detector as i/p to form an ordered list of edgels

• Edge following
– process takes the entire edge strength or gradient image as i/p &
produces geometric primitives such as lines or curves

© ankush agarwal 45
Segmentation (Discontinuity  Edge  Derivative)

• First Order Derivative/Gradient Methods


– Robert operator
– Sobel operator
– Prewitt operator
• Second Order Derivative
– Laplacian
– Laplacian of Gaussian
– Difference of Gaussian
• Optimal Edge Detection
– Canny Edge Detection

© ankush agarwal 46
Segmentation (Discontinuity  Edge  Derivative)

1 1 1 1 2 2 2
Robert -1 -2 -1 -1 -1 -1
1 1 1 1 2 2 2
1 1 1 1 2 2 2 1 0 0 0 0 0 0 0

2 2 2 2 1 1 1 0 -1 1 2 1 1 1 1

2 2 2 2 1 1 1 G45º SH PH
2 2 2 2 1 1 1 -1 0 1 -1 0 1
0 1
2 2 2 2 1 1 1 -2 0 2 -1 0 1
-1 0
I -1 0 1 -1 0 1
G-45º
SV PV
Sobel Prewitt

© ankush agarwal 47
Segmentation (Discontinuity  Edge  Derivative)

• Motivation
– Detect sudden changes in image intensity
– Gradient: sensitive to intensity changes
• Gradient T
 f f 
f   
 x y 

© ankush agarwal 48
Segmentation (Discontinuity  Edge  Derivative)

• The gradient of the image I at location (x, y) is the vector


 I (x, y) 
Gx   x 
I      
 y 
G I (x, y) 
 y 
• Magnitude
| I | Gx2  G y2
• Gradient
 Gy 
 (x, y)  tan 1  
 x
G

© ankush agarwal 49
Segmentation (Discontinuity  Edge  Derivative)

• Eg:
– Find the strength & the direction of the edge at the highlighted pixel
– Pixels in gray are 0 and white are 1

Solution
• Derivative is computed by using a 3x3 neighbourhood
– subtract the pixels in the top row from bottom row (x direction)
– similarly obtain the derivative in the y direction
-1 -1 -1 -1 0 1
0 0 0 -1 0 1
1 1 1 -1 0 1
© ankush agarwal 50
Segmentation (Discontinuity  Edge  Derivative)

• Eg:
– Find the strength & the direction of the edge at the highlighted pixel
– Pixels in gray are 0 and white are 1

 I (x, y) 
Gx   x   2 
I       
G y   I (x, y)   2 
 y 

| I | Gx2  G y2  2 2

 Gy 
 (x, y)  tan 
1
  1  45
 x
G

© ankush agarwal 51
Simple edge detection using gradient

• Compute gradient vector at each pixel by convolving image with


horizontal and vertical derivative filters
• Compute gradient magnitude at each pixel
• If magnitude at a pixel exceeds a threshold, report a possible edge
point

© ankush agarwal 52
CANNY EDGE DETECTOR

© ankush agarwal 53
Canny (Characteristics)

• Good Detection : Robustness to noise


– The optimum detector must minimize the probability of false positive as
well as false negative
• Good Localization:
– The edge must be as close as possible to the true edges
• Strong Response Constraint:
– Not too many or too few responses: The detector must return one point
only for each point

© ankush agarwal 54
Canny (Steps)

• Smoothing with Gaussian Filter


• Compute Derivative of filter image
• Find magnitude & orientation of gradient
• Apply Non Maxima Suppression
• Apply Hysteresis Threshold

© ankush agarwal 55
Canny (Steps – Gaussian filter)

• Smoothing with Gaussian filter on Image I(r,c)

© ankush agarwal 56
Canny (Steps - Derivative)

© ankush agarwal 57
Canny (Steps - Magnitude and Orientation)

© ankush agarwal 58
Canny (Steps - Apply Non Maxima Suppression)

© ankush agarwal 59
Canny (Steps - Apply Non Maxima Suppression)

Exploring Pixels for NonMaxima Suppression


Colour Coded Orientation

Gradient Magnitude after


Gradient Magnitude Additive Noise: Dithering NonMaxima Suppression
© ankush agarwal 60
Canny (Steps – Apply Hysteresis Thresholding)

© ankush agarwal 61
Canny (Steps – Apply Hysteresis Thresholding)

© ankush agarwal 62
Canny

• Eg:
– Compute derivative

© ankush agarwal 63
Canny

• Eg:
– Compute magnitude and orientation

-4 -3 -1 0 0 2 1 1 0 0
-3 -4 -3 -1 0 1 2 3 1 0
0 -1 -3 -4 -3 0 1 3 2 1
0 0 -1 -3 -4 0 0 1 1 2
0 0 0 0 -1 0 0 0 0 1

© ankush agarwal 64
Canny

• Eg:
– Apply Non-maxima suppression

4.5 3.2 1.4 0 0 -27 -18 -45 D D


3.2 4.5 4.2 1.4 0 -18 -27 -45 -45 D
0 1.4 4.2 4.5 3.2 D -45 -45 -27 -18
0 0 1.4 3.2 4.5 D D -45 -18 -27
0 0 0 0 1.4 D D D D -45

© ankush agarwal 65
Canny

• Eg:
– Apply Hysteresis Threshold

-27 -18 -45 D D 4.5 0 0 0 0


-18 -27 -45 -45 D 0 4.5 4.2 0 0
D -45 -45 -27 -18 0 0 4.2 4.5 0
D D -45 -18 -27 0 0 0 0 4.5
D D D D -45 0 0 0 0 1.4

© ankush agarwal 66
HOUGH TRANSFORM

© ankush agarwal 67
Hough Transform

• Image and Parameter space

y = mx+c c = -mx+y
variable: x, y variable: m, c
parameter: m, c parameter: x, y
© ankush agarwal 68
Hough Transform

• Eg:

© ankush agarwal 69
Hough Transform

• Step 1:
– Known
• -1.2<=m<=-0.8
• step_m = 0.1

• m = -0.8, -0.9, -1.0, -1.1, -1.2


• c = -mx+y

© ankush agarwal 70
Hough Transform

• Step 2:
– Compute c

(x,y) = (4,1) (x,y) = (3,2) (x,y) = (2,3) (x,y) = (1,4)


c = -4m+1 c = -3m+2 c = -2m+3 c = -m+4
m c m c m c m c
-0.8 4.2 -0.8 4.4 -0.8 4.6 -0.8 4.8
-0.9 4.6 -0.9 4.7 -0.9 4.8 -0.9 4.9
-1.0 5.0 -1.0 5.0 -1.0 5.0 -1.0 5.0
-1.1 5.4 -1.1 5.3 -1.1 5.2 -1.1 5.1
-1.2 5.8 -1.2 5.6 -1.2 5.4 -1.2 5.2

© ankush agarwal 71
Hough Transform

• Step 3:
– Find min and max of c
(x,y) = (4,1) (x,y) = (3,2) (x,y) = (2,3) (x,y) = (1,4)
• Range: 4.2 to 5.8 c = -4m+1 c = -3m+2 c = -2m+3 c = -m+4
• Interval: 0.1 m c m c m c m c
-0.8 4.2 -0.8 4.4 -0.8 4.6 -0.8 4.8
-0.9 4.6 -0.9 4.7 -0.9 4.8 -0.9 4.9
-1.0 5.0 -1.0 5.0 -1.0 5.0 -1.0 5.0
-1.1 5.4 -1.1 5.3 -1.1 5.2 -1.1 5.1
-1.2 5.8 -1.2 5.6 -1.2 5.4 -1.2 5.2

© ankush agarwal 72
Hough Transform

• Step 4:
– Voting

© ankush agarwal 73
Hough Transform

• Step 5:
– Find equation

• m =-1.0
• c = 5.0
• y = -x+5

© ankush agarwal 74
Hough Transform

• Problem
– The slope of line parallel to y – axis is infinity, the computer can not
handle it.
– So, we follow another parameterization of a line
– p = x cos θ + y sin θ

© ankush agarwal 75
Hough Transform

y
6
5
4
3
p = x cos θ + y sinθ
2
Edgels: (0,5), (1,4), (3,2), (3,3), (5,0)
1
0
0 1 2 3 4 5 6 x

© ankush agarwal 76
Hough Transform

p = x cos θ + y sinθ

p = 0 cos θ + 5 sin θ (0,5)


p = 1 cos θ + 4 sin θ (1,4)
p = 3 cos θ + 2 sin θ (3,2)
p = 3 cos θ + 3 sin θ (3,3)
p = 5 cos θ + 0 sin θ (5,0)

© ankush agarwal 77
Hough Transform

0 cos θ + 5 sin θ 1 cos θ + 4 sin θ 3 cos θ + 2 sin θ 3 cos θ + 3 sin θ 5 cos θ + 0 sin θ

0 0 1 3 3 5

30 2.5 2.9 3.9 4 4.3

45 3.5 3.5 3.5 4.2 3.5

60 4.3 3.9 3.2 4 2.5

90 5 4 2 3 0

© ankush agarwal 78
Hough Transform

• The equation for the edge will be:

3.5 = x cos 45 + y sin 45

© ankush agarwal 79
GLA UNIVERSITY

DIGITAL IMAGE PROCESSING

By:
Dr. Ankush Agarwal
Outline

• Morphological Image Processing


– Introduction, Logical Operations involving Binary Images,
– Dilation and Erosion, Opening and Closing, The Hit-or-Miss Transformation,
– Morphological Algorithms – Boundary Extraction, Region Filling, Extraction of
Connected Components, Convex Hull, Thinning, Thickening
• Image Segmentation
– Point, Line & Edge detection, Thresholding, Region-based Segmentation,
– Region Extraction - Pixel Based Approach & Region Based Approach,
– Edge and Line Detection - Basic Edge Detection, Canny Edge Detection,
– Edge Linking - Hough Transform.
• Representation & Description
– Representation - Boundary Following, Chain Codes,
– Boundary Descriptors - Shape Numbers

© ankush agarwal 2
IMAGE REPRESENTATION AND DESCRIPTION

© ankush agarwal 3
Image Representation and Description

• To represent and describe information embedded in an image in


other forms that are more suitable to visualize and understand

• Benefits
– Easier to understand
– Require fewer memory
– faster to be processed

• What kind of information we can use?


– Boundary, shape
– Region
– Texture
– Relation between regions
© ankush agarwal 4
Image Representation and Description

• Segmentation techniques yield raw data in the form of pixels


along a boundary or pixels contained in a region
• After segmentation, the image needs to be described and
interpreted
– Representation
• An object may be represented by its internal/external characteristics
– Description
• The object boundary may be described by its length, orientation, etc
• The features that represent the image are used as descriptors

© ankush agarwal 5
Border

• An ordered list of points representing the boundary of an object


• Boundary as a sequence of connected points

© ankush agarwal 6
Border (Algo)

• Step 1: Start scanning row-wise from top left corner of the image
• Step 2: Mark the first object pixel obtained as the start pixel
• Step 3: Based on the previous pixel (p) and the current pixel (c),
find the next pixel (n)
– n is found by searching in the neighbourhood of c, clockwise starting from
previous pixel p
• Step 4: Mark the current pixel as previous pixel & the next pixel
as the current pixel
• Step 5: Go to step 3

© ankush agarwal 7
Border (Eg)

1 1 1
p c
1 1
1 1
1 1
1 1 1 1

© ankush agarwal 8
Border (Eg)

1 1 1
p c
1 1
1 1
1 1
1 1 1 1

© ankush agarwal 8
Border (Eg)

1 1 1
p c
1 1
1 1
1 1
1 1 1 1

© ankush agarwal 8
Border (Eg)

1 1 1
p c
1 1
1 1
1 1
1 1 1 1

© ankush agarwal 8
Border (Eg)

1 1 1
p c
1 1
1 1
1 1
1 1 1 1

© ankush agarwal 8
Border (Eg)

1 1 1
p c
1 1
1 1
1 1
1 1 1 1

© ankush agarwal 8
Chain Code

• The boundary is a good representation of an object shape


• It represents an object boundary by a connected sequence of
straight line of specified length and direction
• The direction of each segment is coded by using a numbering
scheme as shown below

© ankush agarwal 9
Chain Code

• Eg:
– Find the 4 directional Chain Code

Solution
• 1101101030332330322212
© ankush agarwal 10
Chain Code

• Eg:
– Find the 8 directional Chain Code

Solution
• 22120207656764443
© ankush agarwal 11
Chain Code (Problem)

• The resulting chain codes are quite long


• Any small change along the boundary due to noise causes
changes in the code
• Dependent on the starting point
• Dependent on the orientation

© ankush agarwal 12
Chain Code

• To use boundary representation in object recognition, we need to


achieve invariance to starting point and orientation

• For this, we use


– Normalized codes
• To overcome the problem of starting point
– Differential codes
• To make rotational invariant

© ankush agarwal 13
Chain Code  Normalization

Sort
33001122 00112233
30011223 01122330
00112233 11223300
01122330 12233001
33001122
11223300 22330011
12233001 23300112
22330011 33001122
First row gives the normalized chain code: 00112233 23300112 30011223

© ankush agarwal 14
Chain Code  Differential

• The first difference of a chain code


– counting the number of direction change (in counter-clockwise) between 2
adjacent elements of the code
• Eg
– a chain code: 10103322
– The first difference: 3133030
– Treating a chain code as a circular sequence, we get the first difference:
31330303

© ankush agarwal 15
Chain Code  Differential

• The shape number of a boundary obtained from a chain code is


defined as the smallest magnitude of the circular first difference
• The order of the shape number is defined as the number of digits
in its representation

© ankush agarwal 16
Chain Code  Differential

• Eg:
– Find the shape number & order of the given boundary

Solution
• 4-direction chain code: 0 3 0 3 2 2 1 1
• First difference: 3 1 3 3 0 3 0
• Circular first difference: 3 1 3 3 0 3 0 3
• Shape number: 0 3 0 3 3 1 3 3
• Order: 8

© ankush agarwal 17

You might also like