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

CV_Lecture_2-DD-Don

The document provides an overview of digital image processing with a focus on image topology, particularly connected component labeling and its significance in object recognition. It explains concepts such as pixel adjacency, paths, equivalence relations, and various distance metrics, including Euclidean and Chamfer distances. Additionally, it outlines the algorithm for connected component labeling and the application of the Matlab bwlabel function for processing binary images.

Uploaded by

Noweto
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)
6 views

CV_Lecture_2-DD-Don

The document provides an overview of digital image processing with a focus on image topology, particularly connected component labeling and its significance in object recognition. It explains concepts such as pixel adjacency, paths, equivalence relations, and various distance metrics, including Euclidean and Chamfer distances. Additionally, it outlines the algorithm for connected component labeling and the application of the Matlab bwlabel function for processing binary images.

Uploaded by

Noweto
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/ 36

Digital Image

Processing
Image Topology

Dr Wafaa Shalash
Introduction
◼ Definition: The study of properties of a figure that are
unaffected by any deformation, as long as there is no
tearing or joining of the figure.
◼ Digital topology deals with the topological properties of
digital image and provides a sound mathematical basis for
image processing operations such as image thinning,
border following and connected component labelling.
Matrix structure is also a consistent mathematical
framework for image processing

Information If you do any process, resize


about rotate
main Basics these parts will stay in image
component of
img

A region with 2 holes A region with 3 connected


components (objects) 2
Another example
We will Focus in connected
Component
◼ How many bacteria here?

3
Simple Example : Count number of Coins

N = 22
Each connected part take a
specific label

The labeling of the connected components of an image


Connected ◼
is a fundamental processing step in object recognition.
Component Pixels which belong to the same connected component
are grouped together and indexed with a unique label,
Labeling as can be seen in figure.
Neighbors and Adjacency
◼ We often have interests in classifying pixels into
different categories
◼ Neighbourhoods:

4 4-nghbr 8 8-nghbr

◼ Two pixels P and Q are 4-adjacent if they are


4-neighbours of one another, and 8-adjacent if
they are 8-neighbours of one another.
• • • •
4-adjacent • P • • P • 8-adjacent

• • • • 6
Paths
◼ Suppose that P and Q are any two pixels (not
necessarily adjacent), and suppose P and Q can
be joined by a sequence of pixels as shown:

4-adjacent 8-adjacent

4-connected 8-connected

◼ If the path contains only 4-adjacent pixels, then


P, Q are 4-connected.
◼ If the path contains 8-adjacent pixels, then P and
Q are 8-connected
7
Components

◼ A set of pixels all of which are 4-connected to


each other is called a 4-component; if all the
pixels are 8-connected the set is an 8-
component.
One 8-component

4-component
4-component
8
Formal Definition of a Path

◼ A 4-path from P to Q is a sequence of pixels

P = p0, p1, p2, …, pn = Q

such that for each i=0,1,…, n-1, pixel pi is 4-


adjacent to pixel pi+1.

◼ An 8-path is where the pixels in the sequence


connecting P and Q are 8-adjacent
9
Properties of Connectivity –
Equivalence Relations
◼ A relation x~y between two objects x and y is
an equivalence relation if the relation is
❑ Reflexive:

❑ Symmetric:

❑ Transitive:

◼ Examples for equivalence relation?


◼ Examples that are not equivalence relation?
10
Equivalence Relations
◼ Some ◼ Examples of some
examples: relations which are not
—Numeric equivalence:
equality —Personal relations
—Set cardinality —Subset relation
—Connectedness —Pixel adjacency
◼ The importance of the equivalence relation concept
is that it allows us a very neat way of dealing with
issues of connectedness.
◼ Equivalence class: the set of all objects equivalent
to each other.
11
Connected Component Labelling
◼ Define the components of a binary image as
being the equivalence classes of the
connectedness equivalence relation.
◼ Finding all equivalence classes of connected
pixels in a binary image is called connected
component labelling.
◼ The result of connected component labeling
is another image in which everything in one
connected region is labelled "1" (for
example), everything in another connected
region is labelled "2", etc.
12
Connected Component Labelling (con’d)
◼ Labelling all the 4-components of a binary
image, starting a the top left and working
across and down.
❑ “Scan” the image row by row moving across from
left to right.
❑ Assign labels to pixels in the image; these labels
will be the numbers of the components of the
image.
◼ A pixel in the image will be called a
foreground pixel (fp); a pixel not in the image
will be called a background pixel (bp).
13
Connected Component Labelling: Algorithm
1. Check the state of p. If it is a bp, move on to the
next scanning position. If it is fp, check the state
of u and l. If they are both bp, assign p a new
label.
❑ If only one of u and l are fp, assign the label to p
❑ If both u and l are fp, but different labels, assign
either label to p, and make the 2 labels equivalent. u
2. At the end of the scan, all foreground pixels l p
have been labelled, but some labels may be
equivalent. Then sort the labels into
equivalence classes, and assign a different label
to each class.
3. Do a second pass through the image, replacing
the label on each foreground pixel with the label
assigned to its equivalence class in the previous
step
14
Example 1
First foreground pixel in 2nd row
The first foreground pixel Upper neighbor : background
Upper neighbor : non-existent Left neighbor : non-existent
Left neighbor : background
Step 1.

2nd foreground pixel in 2nd row 3rd foreground pixel in 2nd row
Upper neighbor : foreground Upper neighbor : background
Left neighbor : foreground Left neighbor : background 15
1st foreground pixel in 3rd row:
1st foreground pixel in 3rd row: Upper neighbor :foreground ( label 3)
Upper neighbor :background Left neighbor : foreground (label 4)
Left neighbor : background

4-neighb
our
Step 2. We have the following equivalent classes of labels
4-connected
{1,2} and {3, 4,5}

Assign label 1 to the first class, and


label 2 to the second class

Step 3. Each pixel with labels 1 or 2 from the first step will be
assigned label 1, and each pixel with labels 3, 4, or 5
from the first step will be assigned label 2 16
Example 2
Original Binary image Pass 1:

in this path,
he take
the lift

Pass 2:

17
Example 3
Original Binary image Pass 1:

Pass 2:

Based on 4-Connected or
8-connected ?
18
Matlab bwlabel Function
You have to do Segmentation,
before
Connected Component
Figure after seg number of connected comp
◼ Syntax: (BW) (4or8)
L = bwlabel(BW,n)
[L,num] = bwlabel(BW,n)
◼ Description:
❑ L = bwlabel(BW,n) returns a matrix L, of the same size as
BW, containing labels for the connected objects in BW. n can
have a value of either 4 or 8, where 4 specifies 4-connected
objects and 8 specifies 8-connected objects (defaults to 8).
❑ The elements of L are integer values greater than or equal to
0. The pixels labeled 0 are the background. The pixels
labeled 1 make up one object, the pixels labeled 2 make up a
second object, and so on.
❑ [L,num] = bwlabel(BW,n) returns in num the number of
connected objects found in BW.
◼ See the supplemental notes on using lookup table.

19
Distances and Metrics

◼ A distance function d(x,y) is called a metric if


it satisfies the following:
❑ 1. d (x, y ) = d ( y, x ) (symmetry)
❑ 2. d (x, y )  0 and d (x, y ) = 0 iff x = y (positivity)
❑ 3. d (x, y ) + d ( y, z )  d (x, z ) (the triangle inquality)
◼ A standard distance metric is Euclidean
distance (a straight line between 2 points)
d ( x, y ) =
(x1 − y1 ) + (x2 − y2 )
2 2

where x = (x1 , x2 ) and y = ( y1 , y2 )


20
Distance Metrics for Grid

d 8 ( x, y ) d 4 ( x, y )

◼ The Euclidean distance is 52 + 2 2  5.39


◼ For 4-path and 8-path?
❑ d 4 (x, y ) = x1 − y1 + x2 − y2 (taxicab metric)
❑ d8 (x, y ) = max  x1 − y1 , x2 − y2 

21
The Distance Transform
◼ How to find the distance of every pixel from a region
R?
◼ A well-known method is Chamfering
◼ Algorithm: 
❑ Given: subset S of image
❑ Initialization: elements of S contain 0, and for others.
❑ Step1: Row by row, from top to bottom and left to right:


F ( p) = min F ( p), M f ( p, q) + F (q)
qN p( )

❑ Step2: Row by row, from bottom to top and right to left:
F ( p) = min F ( p), M b ( p, q) + F (q)
qN ( p )

22
Chamfer distance
• Average distance to nearest feature

I = Set of points in image

T = Set of points on (shifted) template

d I (t ) = Minimum distance between point t


and some point in I

Kristen Grauman, UT-Austin


Chamfer distance

Kristen Grauman, UT-Austin


Chamfer distance
• Average distance to nearest feature

How is the measure


different than just
filtering with a mask
having the shape
points?

How expensive is a
naïve
implementation?

Edge image

Kristen Grauman, UT-Austin


Distance transform
Image features (2D) Distance Transform
1 0 1 2 3 4 3 2
1 0 1 2 3 3 2 1
1 0 1 2 3 2 1 0
1 0 0 1 2 1 0 1
2 1 1 2 1 0 1 2
3 2 2 2 1 0 1 2
4 3 3 2 1 0 1 2
5 4 4 3 2 1 0 1

Distance Transform is a function D() that for each image


pixel p assigns a non-negative number D( p) corresponding to
distance from p to the nearest feature in the image I
Features could be edge points, foreground points,…
Source: Yuri Boykov
Distance transform

edges
original distance transform

Value at (x,y) tells how far


that position is from the
nearest edge point (or other
binary mage structure)
>> help bwdist

Kristen Grauman, UT-Austin


Distance transform (1D)

// 0 if j is in P, infinity otherwise

Adapted from D. Huttenlocher


Distance Transform (2D)

Adapted from D. Huttenlocher


Chamfer distance
• Average distance to nearest feature

Edge image Distance transform image

Kristen Grauman, UT-Austin


Chamfer distance

Edge image Distance transform image

Fig from D. Gavrila, DAGM 1999 Kristen Grauman, UT-Austin


Chamfer distance:
properties
• Sensitive to scale and rotation
• Tolerant of small shape changes, clutter
• Need large number of template shapes
• Inexpensive way to match shapes
Masks for Chamfering

◼ Mask1: 1
1 0 0 1
1
Forward mask, Mf Backward mask, Mb

◼ Mask2: 3-4 chamfer (most popular)


4 3 4
3 0 0 3
4 3 4
Forward mask, Mf Backward mask, Mb
33
Masks for Chamfering (con’d)

◼ Mask 3:
11 11
11 7 5 7 11
5 0 0 5
11 7 5 7 11
11 11

Forward mask, Mf Backward mask, Mb

34
Example
     
◼ Initialization:
  0 0  
(using 3-4 chamfer)
   0  
4 3 4    0  
fw
3 0 3 bw    0  
4 3 4      

◼ Step1: ???
qN p( )

F ( p) = min F ( p), M f ( p, q) + F (q) 
◼ Step2: ??? F ( p) = min F ( p), M b ( p, q) + F (q)
qN ( p )

35
Summary

◼ We discussed
❑ Neighbors and Adjacency
❑ Definition of path
❑ Equivalence relation
❑ Component labeling
❑ Distance metrics
◼ Euclidean distance
◼ Metrics for 4- and 8-path
◼ Chamfering

36

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy