Computer Vision - Unit-2
Computer Vision - Unit-2
SHAPES s REGIONS
CONTENTS
Occlusion Handling
INTRODUCTION
Purpose
Key Steps
•Connectedness
•Labeling s Counting
•Size Filtering
•Distance Functions
•Skeletons s Thinning
BINARY SHAPE ANALYSIS
Applications
•Counting cells in a microscope image.
•Detecting defects in manufacturing parts.
•Counting and classifying traffic vehicles in surveillance.
•Recognizing handwritten characters.
•Medical imaging for tumor boundary extraction.
BINARY IMAGES – 4 Connectivity
0010
1110
0100
BINARY IMAGES – 4 Connectivity
0 01 0
1110
0100
BINARY IMAGES – 4 Connectivity
0 01 0
1110
0100
BINARY IMAGES – 4 Connectivity
0 01 0
1110
0100
BINARY IMAGES – 4 Connectivity
0 01 0
1 11 0
0100
BINARY IMAGES – 4 Connectivity
0010
1110
0100
BINARY IMAGES – 4 Connectivity
0010
1110
0100
BINARY IMAGES – 4 Connectivity
0010
1110
0100
BINARY IMAGES – 4 Connectivity
0010
1110
0100
BINARY IMAGES – 4 Connectivity
0010
1100
0100
BINARY IMAGES – 4 Connectivity
0010
1100
0100
BINARY IMAGES – 4 Connectivity
0010
1100
0100
BINARY IMAGES
Original Image
BINARY IMAGES
Identified Object
BINARY IMAGES – 8 Connectivity
1 0 0 0 1
0 1 0 1 0
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1
OBJECT LABELING & COUNTING
How It Works
Input: A binary image where foreground pixels (value = 1)
represent objects, and background pixels (value = 0) represent
empty space.
Connected Component Analysis:
•Uses 4-connectivity or 8-connectivity rules to determine
which pixels belong to the same object.
Assign Labels:
•Each connected object gets a unique label (e.g., Object
1, Object 2, etc.).
Counting:
•Simply counting the number of labels gives the total
number of objects in the image.
OBJECT LABELING & COUNTING
SIZE FILTERING
Purpose
•To eliminate noise (tiny unwanted objects) or irrelevant large
regions.
•To keep only the objects that match the expected size range for
analysis.
SIZE FILTERING
How It Works
Object Labelling
• Identify and label all connected components in the binary image.
Size Measurement
• Calculate the size of each object (usually the number of pixels in it).
Filtering
• Remove objects whose size is less than a minimum threshold or
greater than a maximum threshold.
Output
• A cleaned binary image containing only the objects of interest
SIZE FILTERING
0 1 2 . . . 400
.
1
B
2 A
.
.
.
. C
400
SIZE FILTERING
DISTANCE FUCNTIONS
distance transform
00000 00000 00000
01110 01110 01110
01110 01110 01210
01110 01110 01110
00000 00000 00000
DISTANCE FUCNTIONS – How to Calculate?
Local Maxima
DISTANCE FUCNTIONS – How to Calculate?
distance
transform
0000000 0000000 0000000 0000000
0111110 0111110 0111110 0111110
0111110 0111110 0122210 0122210
0111110 0111110 0121210 0123210
0111110 0111110 0122210 0122210
0111110 0111110 0111110 0111110
0000000 0000000 0000000 0000000
DISTANCE FUCNTIONS – How to Calculate?
Local Maxima
DISTANCE FUCNTIONS – Use?
000000
0
011111
0 Data compression (store only peaks instead of whole
shape).
012221
0 Reducing storage space.
012321
0
012221
Regenerating the object
00000 From stored maxima, apply downward propagation
until full shape is reconstructed.
01110
01210
01110
00000
DISTANCE FUCNTIONS
Steps
Convert binary object to distance transform.
Find local maxima (peaks).
Store only maxima (compressed form).
Reconstruct full object by spreading values downward.
DISTANCE FUCNTIONS
00000
01110
01110
01110
00000
DISTANCE FUCNTIONS
distance transform
00000 00000
01110 01110
01110 01210
01110 01110
00000 00000
DISTANCE FUCNTIONS
00000 00000
01110 01110
2
01110 01210
01110 01110
00000 00000
DISTANCE FUCNTIONS
00000 00000
01110 01110
2
01110 01210
01110 01110
00000 00000
DISTANCE FUCNTIONS
00000 00000
01110 01110
2
01110 01210
01110 01110
00000 00000
DISTANCE FUCNTIONS
Original Object
11111
11111
11111
SKELETONS AND THINNING
Original Object
11111
11111
11111
Skeleton
00100
00100
00100
SKELETONS AND THINNING
•In the real world, objects rarely look exactly the same every
time.
•For example:
•Handwritten letters → every person writes “A” differently.
•Human body → people move, bend, and change poses.
•Medical images → organs may shift or deform but are still
the same organ.
•Deformable shape analysis helps us recognize these as the
same class of object.
DEFORMABLE SHAPE ANALYSIS – How?
Occlusion Handling
CONTENTS
SHAPES s REGIONS
Region-based
Binary Shape Boundary-based Deformable Shape
Shape
Analysis Shape Analysis Analysis
Analysis
ReRgeigoinonDDese
Connectedness Boundary Tracking Active Contours
csrcipritpotrosrs
Labeling C Procedures CMenotmroeidnatsl
Moments
Counting Size Boundary
Filtering Distance Descriptors
Functions Boundary Length
Skeletons C Advanced Shape
Chain Codes
Models
Fourier Descriptors
•Reduced Computation:
•Shape Analysis:
•Compression:
•Recognition:
•Foundation for Other Algorithms
BOUNDARY TRACKING PROCEDURES
•Moore-Neighbour Tracing
0 0 0 0 0
Algorithm: 0 1 1 1 0
0 1 1 1 0
0 1 1 1 0
0 0 0 0 0
•Moore-Neighbour Tracing
0 0 0 0 0
Algorithm: 0 1 1 1 0
0 1 1 1 0
0 1 1 1 0
000 0 0
Input Image
0 0 0 0 0
0 1 1 1 0
0 1 1 1 0
0 1 1 1 0
0 0 0 0 0
Freeman Code
3 2 1
4 * 0
5 6 7
BOUNDARY TRACKING PROCEDURES
Input Image
00000
011 1 0
01110
01110
00000
Freeman
Code
NW N NE
3 2 1 W * E
4 * 0 SW S SE
5 6 7
BOUNDARY TRACKING PROCEDURES
Input Image
00000
011 1 0 000
01110 0 11
0111 011
0
00000
Freeman
Code
NW N NE Final Freeman Code Output
3 2 1 W * E
4 * 0 SW S S
5 6 7 E
BOUNDARY TRACKING PROCEDURES
Input Image
00000
011 1 0 000
01110 0 11
0111 011
0
0000
0
Freeman
Code
5 6 7
NW N NE
3 2 1 W * E
4 * 0 SW S SE
Final
Freeman
Code Output
0,
BOUNDARY TRACKING PROCEDURES
Input Image
0 0000
0 11 1 0 000
0 1110 1 11
0 111 111
0
0 000
0
Freeman
Code
5 6 7
NW N NE
3 2 1 W * E
4 * 0 SW S SE
Final
Freeman
Code Output
0,
BOUNDARY TRACKING PROCEDURES
Input Image
0 0000
0 11 1 0 000
0 1110 1 11
0 111 111
0
0 000
0
Freeman
Code
5 6 7
NW N NE
3 2 1 W * E
4 * 0 SW S SE
Final
Freeman
Code Output
0 , 0,
BOUNDARY TRACKING PROCEDURES
Input Image
0 0 000
0 1 11 0 000
0 1 110 1 10
0 1 11 110
0
0 000
0
Freeman
Code
5 6 7
NW N NE
3 2 1 W * E
4 * 0 SW S SE
Final
Freeman
Code Output
0 , 0,
BOUNDARY TRACKING PROCEDURES
Input Image
0 0 000
0 1 11 0 000
0 1 110 1 10
0 1 11 110
0
0 000
0
Freeman
Code
5 6 7
NW N NE
3 2 1 W * E
4 * 0 SW S SE
Final
Freeman
Code Output
0 , 0, 6,
BOUNDARY TRACKING PROCEDURES
Input
Image
110
0 000
0
0 111
0 1
0 11 0 110
0 111 110
0
0 000
0
Freeman
Code
3 2 1 4 * 0
5 6 7
NW N Final Freeman Code Output
0 , 0, 6,
NE
W * E
SW S
SE
BOUNDARY TRACKING PROCEDURES
Input
Image
110
0 000
0
0 111
0 1
0 11 0 110
0 111 110
0
0 000
0
Freeman
Code
3 2 1 4 * 0
5 6 7
NW N Final Freeman Code Output
0 , 0, 6, 6,
NE
W * E
SW S
SE
BOUNDARY TRACKING PROCEDURES
Input
Image
0 000 110
0
0 111
0
0 1110 110
0 1 11 0 000
0 0000
Freeman
Code
5 6 7
NW N NE
3 2 1 W * E
4 * 0 SW S SE
Final
Freeman
Code Output
0 , 0, 6, 6,
BOUNDARY TRACKING PROCEDURES
Input
Image
0 000 110
0
0 111
0
0 1110 110
0 1 11 0 000
0 0000
Freeman
Code
5 6 7
NW N NE
3 2 1 W * E
4 * 0 SW S SE
Final
Freeman
Code Output
0 , 0, 6, 6, 4,
BOUNDARY TRACKING PROCEDURES
Input
Image
0 000 111
0
0 111
0
0 1110 111
0 11 1 0 000
0 0000
Freeman
Code
5 6 7
NW N NE
3 2 1 W * E
4 * 0 SW S SE
Final
Freeman
Code Output
0 , 0, 6, 6, 4,
BOUNDARY TRACKING PROCEDURES
Input
Image
0 000 111
0
0 111
0
0 1110 111
0 11 1 0 000
0 0000
Freeman
Code
5 6 7
NW N NE
3 2 1 W * E
4 * 0 SW S SE
Final
Freeman
Code Output
0 , 0, 6, 6, 4, 4,
BOUNDARY TRACKING PROCEDURES
Input
Image
0000 011
0
0111
0
01110 011
011 1 0 000
00000
Freeman
Code
5 6 7
NW N NE
3 2 1 W * E
4 * 0 SW S SE
Final
Freeman
Code Output
0 , 0, 6, 6, 4, 4,
BOUNDARY TRACKING PROCEDURES
Input
Image
0000 011
0
0111
0
01110 011
011 1 0 000
00000
Freeman
Code
5 6 7
NW N NE
3 2 1 W * E
4 * 0 SW S SE
Final
Freeman
Code Output
0 , 0, 6, 6, 4, 4, 2,
BOUNDARY TRACKING PROCEDURES
Input
Image
0000 011
0
0111
0
011 1 0 011
0111 011
0
0000
0
Freeman
Code
3 2 1 4 * 0
5 6 7
NW N Final Freeman Code Output
0 , 0, 6, 6, 4, 4, 2,
NE
W * E
SW S
SE
BOUNDARY TRACKING PROCEDURES
Input
Image
0000 011
0
0111
0
011 1 0 011
0111 011
0
0000
0
Freeman
Code
3 2 1 4 * 0
5 6 7
NW N Final Freeman Code Output
0 , 0, 6, 6, 4, 4, 2, 2
NE
W * E
SW S
SE
BOUNDARY TRACKING PROCEDURES
Freeman
Code
NW N NE
3 2 1 W * E
4 * 0 SW S SE
5 6 7
BOUNDARY TRACKING PROCEDURES
Types
Boundary Length (Perimeter)
Fourier Descriptors
Chain Codes
BOUNDARY TRACKING PROCEDURES
Freeman
Code
NW N NE
3 2 1 W * E
4 * 0 SW S SE
5 6 7
BOUNDARY DESCRIPTORS
Types
Boundary Length (Perimeter)
Fourier Descriptors
Chain Codes
BOUNDARY LENGTH MEASURES
How it is calculated:
Count Boundary Pixels
Connectivity Adjustment (For 4-connectivity: each step is 1 unit)
(For 8-connectivity: each step is 1 unit for Hoz/Vert
√2 units for Diagonal
BOUNDARY LENGTH MEASURES
Example-1
4 Connectivity
Input Image Walk around the boundary clockwise
0000 From (1,1) → go right → (1,2), (1,3)
0 Go down → (2,3), (3,3)
0111 Go left → (3,2), (3,1)
0 Go up → (2,1), back to (1,1)
0111 Step counting (Edges, not pixels)
0 Top edge : 3 steps (between top boundaryls
0111 pixe Right edge : 3 steps (downwards)
0 along right side) Bottom edge : 3 steps
0000 (moving left along bottom side) Left edge
0 : 3 steps (upwards along left side)
So total = 3 + 3 + 3 + 3 = 12
BOUNDARY LENGTH MEASURES
Example-1
8 Connectivity
Input Image Walk around the boundary clockwise
0000 From (1,1) → go right → (1,2), (1,3)
0 Go down → (2,3), (3,3)
0111 Go left → (3,2), (3,1)
0 Go up → (2,1), back to (1,1)
0111 Step counting (Edges, not pixels)
0 Top edge : 3 steps (between top boundaryls
0111 pixe Right edge : 3 steps (downwards)
0 along right side) Bottom edge : 3 steps
0000 (moving left along bottom side) Left edge
0 : 3 steps (upwards along left side)
So total = 3 + 3 + 3 + 3 = 12
BOUNDARY LENGTH MEASURES
Example-2
4 Connectivity
Input Image Walk around the boundary clockwise
0000 (1,1)
0 B (2,2)
0100
C (3,3)
0
0010
0
0001
0
0000
0
A
A(1,1) → Right (2,2 → 2,3) , Down (2,3 → 3,3)
B(2,2). Distance = 2 units.
To reach
B, we
must So total = 2 + 2 = 4 Units
step:
Right
(1,1 →
1,2) ,
Down
(1,2 →
2,2)
Distance
=2
units.
B(2,2) →
C(3,3).
To reach
B, we
must
step:
BOUNDARY LENGTH MEASURES
Example-2
8 Connectivity
Input Image Walk around the boundary clockwise
0000 (1,1)
0 B (2,2)
0100
C (3,3)
0
0010
0
0001
0
0000
0
A
A to B
A(1,1) →
B(2,2) =
one So total = √2 + √2 = 2√2 ≈ 2.82 units.
diagonal
step.
Length
of
diagonal
= √2 ≈
1.41.
B to C
B(2,2) →
C(3,3) =
one
diagonal
step.
Length =
√2 ≈
1.41.
BOUNDARY LENGTH MEASURES
Example-2
8 Connectivity
Input Image Walk around the boundary clockwise
0000 (1,1)
0 B (2,2)
0100
C (3,3)
0
0010
0
0001
0
0000
0
A
A to B
A(1,1) →
B(2,2) =
one So total = √2 + √2 = 2√2 ≈ 2.82 units.
diagonal
step.
Length
of
diagonal
= √2 ≈
1.41.
B to C
B(2,2) →
C(3,3) =
one
diagonal
step.
Length =
√2 ≈
1.41.
BOUNDARY DESCRIPTORS
Why?
To measure object size and shape complexity.
Occlusion Handling
CONTENTS
SHAPES s REGIONS
Occlusion Handling
FOURIER DESCRIPTORS
Step
s Find the Boundary pixels
Get the Boundary Coordinates
Convert to a Complex Number Sequence
Apply the Discrete Fourier Transform
FOURIER DESCRIPTORS
So the first Fourier descriptor gives us the centroid of the shape (2,2).
FOURIER DESCRIPTORS
(2,2) For u = 1, 2, 3… 7
FOURIER DESCRIPTORS
FOURIER DESCRIPTORS
FOURIER DESCRIPTORS
FOURIER DESCRIPTORS
Shape Simplification
You don’t need all frequencies.
Just keep the first few descriptors (say 4–10) → this gives a smooth,
noise-free
approximation of the shape.
CONTENTS
SHAPES s REGIONS
Definition
• It is the study of shapes that can bend, stretch, or change
slightly, while still being recognized as the same object.
•In the real world, objects rarely look exactly the same every time.
•For example:
•Handwritten letters → every person writes “A” differently.
•Human body → people move, bend, and change poses.
•Medical images → organs may shift or deform but are still the same
organ.
•Deformable shape analysis helps us recognize these as the
same class of object.
•Active Contours
ACTIVE CONTOUR
Step 1: Initialization
• Place an initial curve (circle, rectangle, or manual outline) near the
object.
Step 2: Forces Acting on the Snake
• Internal energy: keeps the snake smooth, resists stretching.
• Like tension in a rubber band.
• External energy: pulls snake toward strong edges, lines, or corners.
• Derived from image features (e.g., gradient magnitude).
Step 3: Iteration
• The snake moves step by step:
• If a point is far from an edge → pulled outward until it reaches one.
• If a point hits noise → internal energy keeps it smooth.
Step 4: Convergence
• The snake stops moving when forces balance → it “locks” onto the
boundary.
ACTIVE CONTOUR – Working Prnciple
Example 1:
Numerical Example :
0000000
0111110
0111110
0111110
0000000
ACTIVE CONTOUR – Working Prnciple
Numerical Example :
0000000
0111110
0111110
0111110
0000000
Numerical Example :
0000000
0111110
0111110
0111110
0000000
Numerical Example :
0000000
0111110
0111110
0111110
0000000
Numerical Example :
0000000
0111110
0111110
0111110
0000000
Numerical Example :
0000000
0111110
0111110
0111110
0000000
Numerical Example :
0000000
0111110
0111110
0111110
0000000
Numerical Example :
0000000
0111110
0111110
0111110
0000000
Occlusion Handling
REGION DESCRIPTORS
Input Image
00000
01110
01110
01110
00000
area is G area = 6
REGION DESCRIPTORS
Input Image
00000
01110
01110
01110
00000
Input Image
00000
01110
01110
01110
00000
00000
01110
01110
01110
00000
Find top, bottom, left, right, and diagonal distance from centroid
REGION DESCRIPTORS - CENTROID
PROFILES
Input Image
00000
01110
01110
01110
00000
Find top, bottom, left, right, and diagonal distance from centroid
REGION DESCRIPTORS - CENTROID
PROFILES
Input Image
00000
01110
01110
01110
00000
Find top, bottom, left, right, and diagonal distance from centroid
REGION DESCRIPTORS - CENTROID
PROFILES
Input Image
00000
01110 To top boundary = 1
pixel, To bottom
01110 boundary = 1 pixel, To
left boundary = 1 pixel,
01110 To right boundary = 1
00000 pixel,
Find top, bottom, left, right, and diagonal distance from centroid
REGION DESCRIPTORS - CENTROID
PROFILES
Input Image
00000
01110 To top boundary = 1
pixel, To bottom
01110 boundary = 1 pixel, To
left boundary = 1 pixel,
01110 To right boundary = 1
00000 pixel, Along diagonals
= √2
Find top, bottom, left, right, and diagonal distance from centroid
REGION DESCRIPTORS - CENTROID
PROFILES
Input Image
Find top, bottom, left, right, and diagonal distance from centroid
REGION DESCRIPTORS - CENTROID
Input
PROFILES
Input Image2
Image1
0001000
00000 0011100
01110 0111110
01110 1 1 11 1 1 1
01110 0111110
00000 0011100
0001000
Occlusion Handling
SHAPE MODELS AND SHAPE RECOGNITION
. Shape Models
A shape model is a way to mathematically or structurally
represent the shape of an object so that it can be stored,
analyzed, or compared.
• Think of it like a blueprint of a shape.
• Instead of keeping all the pixels of an object, we store
only the important information about its geometry.
SHAPE MODELS AND SHAPE RECOGNITION
Shape Recognition:
Once shapes are modeled, the next step is recognition →
identifying what the shape is.
How it works:
1. Feature Extraction – Extract important features from the
shape (like boundary length, chain codes, Fourier descriptors,
moments).
2. Matching – Compare these features with stored
models in the database.
3. Classification – Decide which known shape the object
is most similar to.
SHAPE MODELS AND SHAPE RECOGNITION
Input Image
00000
01110
01110
01110
00000
SHAPE MODELS AND SHAPE RECOGNITION
Input Image
Shape Model (Feature Extraction)
00000
Now, instead of storing all 25 pixel values, we extract
shape features: 01110
1.Area = number of "1"s = 9 pixels 01110
2. Perimeter (Boundary length) = 12 units (from tracing 01110
boundary) 00000
3. Centroid (Center point) = (2,2)
4. Chain Code (Clockwise boundary walk): 0,0,1,1,2,2,3,3