IP Digital Geometry L2
IP Digital Geometry L2
IP Digital Geometry L2
Geometry in a
discrete grid
Jayanta Mukhopadhyay
Dept. of CSE,
IIT Kharagpur
Discrete Space and Tiling
l Discrete Space
l Integral coordinate space: Zn
l Digital grid
l A finite subset of integral coordinate space: Gn ⊂ Zn
l represented by a n-D rectangular array
l Tessellation or Tiling
l 2D: A bounded region of a specific shape that fills the
plane with no overlaps and no gaps
l Center of the region lies at a grid point
l Regular tiling: All the space filling units are similar and
of the shape of a regular polygon
2
l Generalization to n-D regular hyper-polyhedron
J. Mukhopadhyay, et al (2013), "Digital Geometry
in Image Processing", CRC Press, April.
l In 3-D: 1 (Rectangular)
l In 4-D: 3
l In n-D, n>4: 1 (Rectangular)
Our focus: Digital geometry in rectangular grid ! 3
2-D or 3-D
Why digital geometry?
ε ε-Neighbour:
p a point q is in N(p),
iff d(p,q) ≤ ε.
p
q
2 3
1 n
N(x;d) is a Norm of d if
N(x;d) = d(x, 0) where x = u – v
Why a metric?
l A bounded and compact neighbourhood around a
point in the space.
l There exists an optimal path between two points,
such that the length of this path is given by the
distance function.
Neighbourhood structure:
Examples
L1 norm
Desirable features:
Isotropy and symmetry:
Isotropic in all directions.
Uniformity:
Identical at all points of the
space. L2 norm
Convexity:
In the sense of Euclidean
geometry.
Self-similar:
Similar structure at varying
resolution. L∞ norm
Acknowledgement: Figure taken from http://en.wikipedia.org/wiki/File:Vector_norms.svg
Geometry built on distances
l Shortest Paths in Euclidean Space
l Straight Lines
l Geodesics on Earth
l Parallel Lines
l Equidistant Ever
l Circle
l Trajectory of a point equidistant from Center
l Least Perimeter with Largest Area
l Conics are distance defined.
Neighbors of Pixels in 2-D
l P = (x,y)
l 4–Neighbours
l N4(P) = {(x–1,y), (x+1,y) , (x,y–1), (x,y+1)}
l Diagonal–Neighbours
l ND(P) = {(x–1,y–1), (x–1,y+1) , (x+1,y–1), (x+1,y+1)}
l 8–Neighbours
l N8(P) = N4(P) U ND(P)
o o o o
For a digital
distance:
o o o o o o
A neighbor is at
o o o o distance 1.
14
4-neighbors 8-neighbors
Digital Distances in 2D
Cityblock:
d4(u, v) = x1+x2 ,
Chessboard:
d8(u, v) = max(x1, x2),
Octagonal (uses non-uniform alternating neighborhoods):
doct(u, v) = max(x1, x2, é2(x1 + x2)/3ù) .
Rosenfeld and Pfaltz ’68
Octagonal Distance
b
d(a,b) = 10
Neighborhood sequence {1,2}
doct(u, v) = max(x1, x2, é2(x1 + x2)/3ù)
2 2 2
2 2 1 2 2
2 1 * 1 2
2 2 1 2 2
2 2 2
Weighted Distance
For u, vÎZ2 and x = |u – v|=(x1, x2),
b a b
a p a Metric Conditions:
a ≤ b, and b ≤ 2a
b a b
e.g.,
q(7,5)
For a=1 and b=1.4,
d<1,2>(p,q)=9.
Euclidean distance:
de(p,q)= 8.6
p(0,0)
Circle of a weighted distance
<1, √2>
Neighbors of Voxels in 3-D
l P = (x,y,z)
l 6–Neighbors (Face),
l 18–Neighbors (Edge) &
l 26–Neighbors (Corner)
B(O; R ) = {x d (O, x ) £ R}
R R
2D
d4 d8
3D
d6 d18 d26
Vertices of octagonal discs:
{ }
a b
2D : 1 2 : permutation of(± R,±
ab
a+b
R)
{ }
a b c
3D : 1 2 3 : permutation of(± R, ±
b+c
a+b+c
R, ±
c
a+b+c
R)
Octagonal Digital Circles
2-D 3-D
27
Connectivity
l Two pixels are Connected if there exists a path
between them.
l Pixels connected to a given pixel form a
Connected Component.
l A Region is a Connected Set of foreground points.
l Foreground & Background
l Foreground: Union of all disjoint Regions in an Image
l Background: Complement of Foreground
l Boundary or Border
l Inner Border: Set of points in R adjacent to complement of R
l Outer Border: Set of points in complement of R adjacent to R 28
4– and 8–Neighbors Dichotomy
l Jordan’s Curve Theorem
l Every simple closed curve divides the
plane into an "interior" region bounded by
the curve and an "exterior" region
containing all far away points
§ Any continuous path connecting a point of one
region to a point of the other intersects that loop
somewhere.
l Digital Jordan’s Curve Theorem
l Deviates from the theorem.
l Use alternate adjacency for interior / exterior
29
J. Mukhopadhyay, et al (2013), "Digital
Geometry in Image Processing", CRC Press,
Limitation of Jordan’s curve
April.
(8,4) (4,8)
A single component Three components 30
0 0 1 0
0 0 1 0
1 1 1 0
0 0 0 0
31
J. Mukhopadhyay, et al (2013), "Digital Geometry
in Image Processing", CRC Press, April.
Chamfering!
p p
For 8-adjacent
(a)
connected
component
(b)
33
Distance Transforms for
Binary Images (d4)
34
35
36
38
39
41
Courtesy: R.C. Gonzalez and R.E Woods © 1992-2008
DT: Properties -2
l If there is only one q ε B with t(p) = d(p, q):
l (a) an element p’ ε F exists such that the disk centered
at p’ totally contains the disk centered at p (disk B is
totally included in disk A)
l (b) elements p’ ε F and q’ ε B exist such that d(p, q) =
d(p’, q’) and p is adjacent to p’
(a) (b) 42
43
Euclidean Sphere
Voxel Data MAT
Approximation
J. Mukhopadhyay, et al (2013), "Digital Geometry
in Image Processing", CRC Press, April.
Shape representation in 2D
l Boundary (Border) Following
l Chain Codes
l Polygonal Approximation using Minimum-
Perimeter Polygons (MPP)
l Polygonal Approximation by Merge/Split
l Signatures
l Boundary Segments
l Skeletons
54
p q ,q q 5
q=r 0 p 4 r the neighborhood of q
0 p 0 p
3 3 4
4
p
a border pixel p with 9, p 5
r7 6 r 5 r
a background q9 p 8 p q 6 6
neighbor at q in an q p8 q 7 7
1 2
3 1
2 0 4 0
5 7
3 6
4-Directional Code 8-Directional Code 58
Need for resampling
l The chain code of the same length as the
perimeter of the object, in many cases too long
l Hence, re-sample the image to a lower resolution
before calculating the code
l The re-sampling also reduces noise sensitivity
59
4-connected or
8-connected.
60
62
63
65
67
69
A = ê x2 y2 1ú
ê ú + 3
êë x3 y3 1úû
sgn(a, b, c ) = det( A) =
ì> 0, if (a, b, c ) is a counterclockwise sequence
ï
í = 0, if the points are collinear
ï < 0, if (a, b, c ) is a clockwise sequence
î
70
l Crawler Vertices:
l White crawler: WC and Black crawler: BC
71
73
l sgn(VL,Bc,V1)=0
l WC=V1=(2,4)
l Next vertex: V2= (3,4) B
74
l BC=V2=(3,4)
l Next vertex V3= (3,3) W
75
76
l WC=V4=(3,3)
l Next vertex V5=(4,3) B
77
l VL = WC = (3,3)
l WC = BC = VL
l Next vertex:
V6=(4,3) B 78
l WC = BC = VL=(3,3)
l V6=(4,3) B
l Condition [B]
l sgn(VL,Wc,V6)=0
l sgn(VL,Bc,V6)=0
l BC=(4,3)
l Next vertex V7=(4,2) W
79
l WC=(3,3), BC=(4,3)
l VL=(3,3)
l V7=(4,2) W
l Condition [C]
l sgn(VL,Bc,V7) < 0
l VL= BC=(4,3)
l WC = BC = VL
l Next vertex V8= (4,2)
80
l WC=(4,3), BC=(4,3)
l VL=(4,3)
l V8=(4,2) w
l Condition [B]
l sgn(VL,Wc,V8)=0
l sgn(VL,Bc,V8)=0
l WC=(4,2)
l Next vertex V9= (4,1)
81
l WC=(4,2), BC=(4,3)
l VL=(4,3)
l V9=(4,1) W
l Condition [B]
l sgn(VL,Wc,V9)= 0
l sgn(VL,Bc,V9)= 0
l WC= (4,1)
l Next vertex V10= (5,1)
82
l WC=(4,1), BC=(4,3)
l VL=(4,3)
l V9=(5,1) W
l Condition [A]
l sgn(VL,Wc,V10) > 0
l VL = WC= (4,1) W
l WC= BC= (4,1)
l Next vertex V11= (5,1)
l And so on ..
83
86
An example of DC and irreducible DC.
Fast polygonal approximation of digital curves using relaxed straightness properties
P Bhowmick, BB Bhattacharya - IEEE TPAMI, 2007
Chain codes and their enumeration for defining DC. (a) Chain codes in 8-
neighborhood connectivity. (b) (1, 2)10756543.
87
(c) (1, 2)10756543(3, 4)76. (d) (2, 1)0756543121
Digital Straight Line Segments
(DSS)
l Let p, q be points of the digital picture subset S, and let pq
denote the (real) line segment between p and q.
l pq lies near S if, for any (real) point (x,y) of pq, there exists a
(lattice) point (i,j) of S such that max {|i - x |,|j - y|} < 1.
l S has the chord property if, for every p, q in S, the chord pq
lies near S..
q
u 𝚫x
𝚫y
v pq lies near S if for any v there exists u
S
and such that max(𝚫x,𝚫y)<1.
p
AZRIEL ROSENFELD, Digital Straight Line Segments. IEEE TRANSACTIONS 88
DSS characterization
l R1: The runs have at most two directions, differing by 45 degrees,
and, for one of these directions, the run length must be 1.
l At most two types of elements and they differ only by unity, modulo eight.
l One of the two element values always occurs singly.
l R2: The runs can have only two lengths: consecutive integers.
l Successive occurrences of the element occurring singly are as uniformly
spaced as possible.
l R3: One of the run lengths can occur only once at a time.
l R4: For the run length that occurs in runs, these runs can
themselves have only two lengths p and p+1, which are consecutive
integers, and so on.
l Except run lengths at two extreme ends (l and r, l, r < (p+1) )
AZRIEL ROSENFELD, Digital Straight Line Segments. IEEE TRANSACTIONS 90
04 1 05 1 04 1 05 1 04 1 05
l=4, r=5, p=4
91
P. Bhowmick and B. B. Bhattacharya, "Fast Polygonal Approximation of Digital Curves Using Relaxed Straightness
Properties," in IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 29, no. 9, pp. 1590-1602, Sept. 2007
Digital curve segmented by
DSS’s
l Segments shown with alternate black and grey fragments.
l Of small lengths.
l Too many fragmentation.
92
P. Bhowmick and B. B. Bhattacharya, "Fast Polygonal Approximation of Digital Curves Using Relaxed Straightness
Properties," in IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 29, no. 9, pp. 1590-1602, Sept. 2007
Approximate DSS (ADSS)
l Used R1
l Modified R2
l Run lengths of non-singly occurred (n) element may vary more than
unity, depending on the minimum length (p).
l But dropped R3 and R4
l To allow longer fragments of DC approximating a straight line
segment.
l DSS is also accepted in the criteria of ADSS
l New Parameters: Run length interval parameters [p,q]
excepting l and r.
Integer computation
l Other hyperparameters: Tolerances
l q-p < d=L (p+1)/2 ⅃ , and l-p, r-p < 𝜖 =L (p+1)/2 ⅃
93
P. Bhowmick and B. B. Bhattacharya, "Fast Polygonal Approximation of Digital Curves Using Relaxed Straightness
Properties," in IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 29, no. 9, pp. 1590-1602, Sept. 2007
P. Bhowmick and B. B. Bhattacharya, "Fast Polygonal Approximation of Digital Curves Using Relaxed Straightness
Properties," in IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 29, no. 9, pp. 1590-1602, Sept. 2007
Not ADSS
l=4, r=5, p=1, q=8
Example
DSS
ADSS
97
P. Bhowmick and B. B. Bhattacharya, "Fast Polygonal Approximation of Digital Curves Using Relaxed Straightness
Properties," in IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 29, no. 9, pp. 1590-1602, Sept. 2007
Polygonization / Polylineation
l Input: A sequence of ADSS.
l Output: Vertices of polygon.
l Algo:
l Merge consecutive sequences following an error criteria.
l Cumulative (Max) area of triangles formed by end points of the ADSS
and the line segment of the merged segment should remain within a
fraction of maximum iso-thetic distance of the merged line segment.
l Represent merged segments as a straight line segment with start
and end points of the start and end ADSS of the sequence.
l Continue till all the ADSS’s are covered.
p2(x2,y2)
p1(x1,y1) diso(p,q) =max{|xe-xs|,|ye-ys|}
q(xe,ye)
98
A few results
99
P. Bhowmick and B. B. Bhattacharya, "Fast Polygonal Approximation of Digital Curves Using Relaxed Straightness
Properties," in IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 29, no. 9, pp. 1590-1602, Sept. 2007
Another example
100
Polygonal approximation by
merging
1. Merge points along boundary until LSE of line fit
exceeds a threshold. Output a line (side of
polygon) with parameters of LSE
2. Repeat Step 1 as long as there are points on the
boundary
3. Intersections of line segments give vertices
Disadvantage
May not produce vertices at inflection points as ‘long’
consume these ‘outlier’ points within the threshold.
101
103
104
l Step 2
l Repeat for all contour points
109
113
Reflection
Translation
116
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Basic morphological
operations
n Erosion Keep general shape
but smooth with
respect to object /
n Dilation background
n combine to
n Opening object
n Closing background
117
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Erosion
n Does the structuring element fit the set?
n erosion of a set A by structuring element B: all z in
A such that B is in A when origin of B=z
A - B = {z|(B)z Í A}
A - B = {z|(B)z Ç A = F} c
118
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Erosion
119
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Erosion
120
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Erosion Example 1
121
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Erosion: Example
Original After
image erosion
with a
disc of
radius 10
After After
erosion erosion
with a with a
disc of disc of
radius 5 radius 20 123
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
A Å B = {z|(Bˆ )z Ç A ¹ Φ}
A Å B = {z|[(Bˆ ) Ç A] Í A} z
126
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Dilation
127
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Dilation Example
128
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Dilation: Example
130
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
What Is Dilation For?
Dilation can repair breaks
132
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Duality
( A - B) = A Å Bˆ
c c
( A Å B) = A - Bˆ
c c
133
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
5 basic structuring elements
134
Courtesy: R.C. Gonzalez and R.E Woods © 1992-2008
Combining erosion and
dilation
n WANTED:
n remove structures / fill holes
n SOLUTION:
n combine erosion and dilation
135
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Erosion followed by dilation:
eliminating irrelevant detail
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
A B = ( A - B) Å B
l eliminates protrusions
l breaks necks
l smoothes contour
137
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Opening
138
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Opening
02-Sep-11 139
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Opening Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Original
Image
Image
After
Opening
140
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Closing
dilation followed by erosion, denoted •
A • B = ( A Å B) - B
l smooth contour
l fuse narrow breaks and long thin gulfs
l eliminate small holes
l fill gaps in the contour
141
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Closing
142
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Closing
143
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Closing Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Original
Image
Image
After
Closing
Image Morphology 144
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Properties
Opening
(i) A°B is a subset (subimage) of A
(ii) If C is a subset of D, then C °B is a subset of D °B
(iii) (A °B) °B = A °B
Closing
(i) A is a subset (subimage) of A•B
(ii) If C is a subset of D, then C •B is a subset of D •B
(iii) (A •B) •B = A •B
( A • B) = A Bˆ
c c
( A B) = A • Bˆ
c c
146
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Hit-or-Miss Transformation ⊛
(HMT)
n find location of one shape among a set of shapes
n ”template matching”
A * B = ( A - B1 ) Ç [ A - B2 ] c
A * B = ( A - B1 ) - ( A Å Bˆ 2 )
148
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Hit-or-Miss transformation
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
B1
B2
Complement Erosion with B2
149
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Application: Boundary
Extraction
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
b ( A) = A - ( A - B)
150
Courtesy: R.C. Gonzalez and R.E Woods © 1992-2008
Boundary / Contour
Extraction
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
151
Courtesy: R.C. Gonzalez and R.E Woods © 1992-2008
Application: Hole Filling
The key equation for region filling is
X k = ( X k -1 Å B) Ç A c
k = 1,2,3.....
Where X0 contains a starting point inside in each
hole hole, B is a symmetric structuring element and
Ac is the complement of A
This equation is applied repeatedly until Xk is equal
to Xk-1
Finally, union of the result with A is performed.
152
Region Filling
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
X k = ( X k -1 Å B) Ç A c
k = 1,2,3,...
153
Courtesy: R.C. Gonzalez and R.E Woods © 1992-2008
Application: Extraction of
connected components
l Y: A connected component in a set A.
l p: A point in Y.
l For extracting connected component Y perform
the following iteratively with X0=p:
154
Connected components
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
155
Courtesy: R.C. Gonzalez and R.E Woods © 1992-2008
Application: Convex Hull
l Convex Set
l A set A is said to be convex if the straight
line segment joining any two points in A
lies entirely within A.
l Convex Hull: H = CH(S)
l Minimal convex superset of S
l Continuous Algorithm
l Convex Deficiency: H – S
156
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Approximate solution!
Convex Hull
l Bi, i=1,2,3, 4 : Four structuring elements
l Perform the following iterative construction for
each structuring element to provide Di at
convergence.
𝑋!$ = 𝑋!"#
$
⊛ 𝐵$ ⋃𝐴, 𝑖 = 1,2,3, 𝑎𝑛𝑑 4; 𝑘 = 1,2,3, …
&
Convex hull
Convex Hull
160
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Thinning
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
A Ä B = A - ( A * B)
= A Ç ( A * B) c
161
Courtesy: R.C. Gonzalez and R.E Woods © 1992-2008
Thinning
162
Courtesy: R.C. Gonzalez and R.E Woods © 1992-2008
Thickening
l Thickening morphological dual of thinning.
𝐴⨀𝐵 = 𝐴⋃(𝐴 ⊛ 𝐵)
l The SE has the same form but 1’s (foreground) and 0’s
(background) interchanged.
l As in thinning, thickening also performed using an
alternate sequence of rotated SEs till convergence.
𝐴⨀ 𝐵 = ⋯ 𝐴⨀𝐵# ⨀𝐵' ⋯ ⨀𝐵(
l Equivalent to thinning background of the thinned
pattern and then taking the complement.
l The thinned background forms the boundary of the
thickened object. 163
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Thickening
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
A • B = A È ( A * B)
164
Courtesy: R.C. Gonzalez and R.E Woods © 1992-2008
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Skeletons
l Where, 𝑆& 𝐴 = 𝐴 ⊝ 𝑘𝐵 − 𝐴 ⊝ 𝑘𝐵 ∘ 𝐵
k successive erosion.
l k is the last iterative step before A erodes to an empty set.
l The set A can be reconstructed by
&
𝐴=) 𝑆# (𝐴)⨁𝑘𝐵
#$%
k successive dilation.
166
Courtesy: P.P. Das, Professor, Dept. of CSE, IIT Kharagpur
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
These pixels
wrongly shown
as object points
after the erosion
with radius 1.
l Shape representation.
l Contour following, Chain Codes
l Polygonization
l Minimum-perimeter polygon (MPP), ADSS algorithm,
Merging and Splitting
l Skeletonization: Thinning
l Morphological Operations
l Dilation, Erosion, Opening, Closing, Hit-&-Mis Transform
l Applications: Smoothing, Convex Hull, Region Filling,
Thinning, Connected Component Extraction, Thinning
Thank You
170