Parallel Banding Algorithm to Compute
Exact Distance Transform with the GPU
Thanh-Tung Cao Ke Tang Anis Mohamed Tiow-Seng Tan
Euclidean Distance
• if p = (p1, p2,..., pn) and
q = (q1, q2,..., qn)
are two points in Euclidean n-space, then the distance from p to q, or from q to p is given by:
Voronoi diagram• A set of points (called seeds, sites,
or generators) is specified beforehand and for each seed there will be a corresponding region consisting of all points closer to that seed than to any other.
Euclidean Distance Transform
100100
Exact Euclidean Distance Transform
• Let Si,j be the nearest site, among all sites in row j, of the pixel (i, j), and let Si = {Si,j | Si,j NULL, j = 0, 1, 2, . . . , n−1} be the collection of such closest sites for all pixels in column i. Note that Si,j is NULL when there is no site in row j.
• Let Pi be the set of sites whose Voronoi regions intersect the pixels in column i. These sites are termed the proximate sites of column i.
Fact 1• Consider column i and let b(i1, j) and b′(i2, j) be
two sites in row j. If |i1 − i| < |i2 − i|, then the Voronoi region of b′ cannot intersect column i.
• This fact means that for each column i, there can be at most one site along a row that can potentially be a proximate site, or basically, Pi ⊆ Si. As a result, |Pi| ≤ n.
Fact 2• Consider column i and let a(i1, j1), b(i2, j2), c(i3, j3)
be any three sites with j1 < j2 < j3. Let the intersection of the perpendicular bisector of a and b and column i be p(i, u), and that of b and c be q(i, v). If u > v then the Voronoi region of b cannot intersect column i.
• When the mentioned situation happens, we say that a and c dominate b on column i. In this case, b Pi.
Fact 3• Let q(i, v) and p(i, u) be two pixels in column i
such that u > v, and let a(i1, j1) and c(i3, j3) be the closest sites to q and p respectively. Then we have j1 ≤ j3.
• This fact means that the proximate sites of column i have their Voronoi regions appear in exactly the same order as when they are sorted by their y-coordinates.
Exact Euclidean Distance Transform
• Phase 1: For each pixel (i, j), compute Si,j .
• Phase 2: Compute the set Pi for each column i using Si.
• Phase 3: Compute the closest site for each pixel (i, j) using Pi
Parallel Banding AlgorithmPhase 1 - Band Sweeping
Band 1 Band 2 Band 3 Band 4
Parallel Banding AlgorithmPhase 1 - Band Sweeping
Band 1 Band 2 Band 3 Band 4
(i,j)
si,j
sii
si,j
Parallel Banding AlgorithmPhase 1 - Band Sweeping
Band 1 Band 2 Band 3 Band 4
Parallel Banding AlgorithmPhase 1 - Band Sweeping
Band 1 Band 2 Band 3 Band 4
Parallel Banding AlgorithmPhase 1 - Band Sweeping
Band 1 Band 2 Band 3 Band 4
Parallel Banding AlgorithmPhase 2 - Hierarchical Merging
Band 1
Band 2
Band 3
Band 4
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
iSi,1
Si,2
Si,3
Si,4
Si,5
Si,6
Si,7
si
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
iSi,1
Si,2
Si,3
Si,4
Si,5
Si,6
Si,7
si
stack
Si,1
Si,2
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
iSi,1
Si,2
Si,3
Si,4
Si,5
Si,6
Si,7
si
stack
Si,1
Si,2
Si,3
(i,v)
(i,u)
v u
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
iSi,1
Si,2
Si,3
Si,4
Si,5
Si,6
Si,7
si
stack
Si,1
Si,2
Si,3
(i,v)
(i,u)
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
iSi,1
Si,2
Si,3
Si,4
Si,5
Si,6
Si,7
si
stack
Si,1
Si,2
Si,3
Si,4
Si,5
Si,6
Si,7
(i,v)
(i,u)
v u
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
iSi,1
Si,2
Si,3
Si,4
Si,5
Si,6
Si,7
si
stack
Si,1
Si,2
Si,4
(i,v)
(i,u) v u
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
iSi,1
Si,2
Si,3
Si,4
Si,5
Si,6
Si,7
si
stack
Si,1
Si,2
Si,4
(i,v)
(i,u)v u
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
iSi,1
Si,2
Si,3
Si,4
Si,5
Si,6
Si,7
si
stack
Si,1
Si,2
Si,4
Si,5
(i,v)
(i,u) v u
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
iSi,1
Si,2
Si,3
Si,4
Si,5
Si,6
Si,7
si
stack
Si,1
Si,2
Si,4
Si,5
Si,6
Si,7
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
iSi,1
Si,2
Si,3
Si,4
Si,5
Si,6
Si,7
si
stack
Si,1
Si,2
Si,4
Si,5
Si,6
Si,7
(i,v)
(i,u)
v u
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
iSi,1
Si,2
Si,3
Si,4
Si,5
Si,6
Si,7
si
stack
Si,1
Si,2
Si,4
Si,5
Si,7
(i,v)
(i,u)
v u
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
iSi,1
Si,2
Si,3
Si,4
Si,5
Si,6
Si,7
si
stack
Si,1
Si,2
Si,4
Si,7
(i,v)
(i,u)v u
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
iSi,1
Si,2
Si,3
Si,4
Si,5
Si,6
Si,7
si
stack
Si,1
Si,2
Si,4
Si,7
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
i
stack
Si,1
Si,2
Si,4
Si,7
Band 2
i
Si,8
Si,9
Si,12
Si,13
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
i
stack
Si,1
Si,2
Si,4
Si,7Band 2 Si,8
Si,9
Si,12
Si,13
Parallel Banding Algorithm• Phase 2 - Hierarchical Merging
Band 1
i
stack
Si,1
Si,2
Si,4
Si,7Band 2
Si,8
Si,9
Si,12Si,13
Parallel Banding Algorithm
Band 1
i
Phase 2 - Hierarchical Merging
proximate texture
Parallel Banding AlgorithmPhase 3 - Block Coloring
Case 1
i
m3
pi
a
b
a
b
Parallel Banding AlgorithmPhase 3 - Block Coloring
Case 2
i
m3
pi
a
b
a
b
Parallel Banding AlgorithmPhase 3 - Block Coloring
Case 2
i
m3
pi
a
b
a
ba
b
a
b
Parallel Banding Algorithm
Parallel Banding Algorithm
Parallel Banding Algorithm
Parallel Banding Algorithm