Professional Documents
Culture Documents
• Labeling regions
(floodfill, connected components)
• Region properties
(area and boundary properties)
75 81 83 96 94
62 74 76 87 100
74 76 80 89 93
53 67 86 90 105
60 77 90 99 115
• Labeling regions
(floodfill, connected components)
• Region properties
(area and boundary properties)
image histogram
...
Example:
[ 6 3 9 7 4 2] [6 9 18 25 29 31]
Steps:
1. Compute normalized histogram (PDF) equal area
int hist[256] = 0…0
float norm[256]
for x, hist[ I(x) ]++
for g = 0 to 255,
norm[g] = hist[g] / npixels
cdf
2. Compute cumulative histogram (CDF)
3. Transform
for x, I(x) = 255*cum[ I(x) ]
q
d{ q 1 ( a ' d )
a’
equal 1
q ( a ')
p( x)dx
spacing
q(q 1 (a'd )) q(q 1 (a' ))
a
a’ a'd a ' /( L 1)
d /( L 1)
a 'd
p' (k )dk '
a'
L-1
old gray level k
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Histogram equalization *
PDF desired
p PDF
equal area
p’
1/(L-1)
a
a1’ a'd a ' /( L 1)
d /( L 1)
a 'd
p' (k )dk '
a'
L-1
old gray level k
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Integral image
• Integral image is a 2D running sum
• S(x,y) = SS I(x,y)
• To compute,
S(x,y) = I(x,y)
- S(x-1,y-1) + S(x-1,y) + S(x,y-1)
• To use,
V(l,t,r,b) = S(l,t) + S(r,b) - S(l,b) - S(r,t)
Returns sum of values inside rectangle
• Note: Sum of values in any rectangle
can be computed in constant time!
Valley separates
light from dark
object 1 object 2
3. Repeat
2. Floodfill
using seed pixel
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Double thresholding example
high threshold removes some foreground combined using floodfill on low threshold
with seeds from high threshold
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Double thresholding
• Labeling regions
(floodfill, connected components)
• Region properties
(area and boundary properties)
Fundamental
operators
Other
operators
DeMorgan’s
Laws
Minkowski
addition:
Minkowski
subtraction:
Intersection of translating
A2 to every point in B
Two examples:
• Algorithm (center-out):
– Flip B horizontally and vertically
(but often B is symmetric, so nothing is changed)
– Move B around
– Anywhere they intersect, turn center pixel on
• Looks like nonlinear convolution
• Algorithm (center-out):
– Move B around Duality b/w dilation
– If there is not complete overlap, and erosion:
turn center pixel off
A B
Without flipping With flipping
• Labeling regions
(floodfill, connected components)
• Region properties
(area and boundary properties)
N4 N8 ND
• 4-adjacency: q N4 ( p) p q
• 8-adjacency: q N8 ( p) p
q
• m-adjacency: q N4 ( p) or
q N D ( p) and N4 ( p) N4 (q)
Example:
48m
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Adjacency
Use different connectedness for
foreground and background to avoid
inconsistency
foreground: D8
background: D4
dumbbell
seed pixel
NO C(P)=C(U) C(P)=n++
4-neighbor 8-neighbor
mask: mask:
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Classical connected
components: first pass
1 1 1 1 1 0 0 0 0 0
0 0 0 0 1 1 1 1 1 0
1 1 1 1 1 2 2 2 2 0
0 0 0 1 0 3 3 3 2 4
0 1 1 1 0 3 5 5 2 4
image components
0 1 2 3 4 5
equivalence table
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Classical connected
components: traverse table
1 1 1 1 1 0 0 0 0 0
0 0 0 0 1 1 1 1 1 0
1 1 1 1 1 2 2 2 2 0
0 0 0 1 0 3 3 3 2 4
0 1 1 1 0 3 5 5 2 4
image components
0 1 2 3 4 5
equivalence table
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Classical connected
components: second pass
1 1 1 1 1 0 0 0 0 0
0 0 0 0 1 1 1 1 1 0
1 1 1 1 1 0 0 0 0 0
0 0 0 1 0 3 3 3 0 4
0 1 1 1 0 3 0 0 0 4
image components
0 1 2 3 4 5
equivalence table
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Another example
from http://www.sciencedirect.com/science/article/pii/S0031320308004573
Connected components
Function labels = ConnectedComponents(image)
// first pass
for y=0 to height-1,
for x=0 to width-1,
pix = image(x,y)
if pix == image(x-1,y) && pix == image(x,y-1)
labels(x,y) = labels(x,y-1)
SetEquivalence(labels(x-1,y), labels(x,y-1))
else if pix == image(x-1,y)
labels(x,y) = labels(x-1,y)
else if pix == image(x,y-1)
labels(x,y) = labels(x,y-1)
else
labels(x,y) = next_label++
// second pass
for y=0 to height-1,
for x=0 to width-1,
labels(x,y) = GetEquivalentLabel( labels(x,y) )
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Connected components
Function SetEquivalence(a, b)
aa = GetEquivalentLabel(a)
bb = GetEquivalentLabel(b)
if aa > bb
equiv[aa] = bb
else if aa < bb
equiv[bb] = aa
Function b = GetEquivalentLabel(a)
if a == equiv[a] return a
else
equiv[a] = GetEquivalentLabel(equiv[a])
return equiv[a]
• Labeling regions
(floodfill, connected components)
• Region properties
(area and boundary properties)
shape of each?
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Other distances
• Mahalanobis
(weight differently along each axis)
• Hausdorff
(distance b/w point sets)
A and B are subsets of S
No=8 Pythagorean:
L = 15.2
Kimura:
L = 15.7
Nd=6
circle with radius = 10 True arc length:
* isothetic (blue) L = 10*p/2 = 15.7
Nd=6
* diagonal (orange) S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Chamfering
• How to approximate “correct” distance
(Euclidean)?
• Along a path,
– Let m be number of isothetic moves (horizontal or vertical)
– Let n be number of diagonal moves
• Define chamfer distance between p and q as
dab = min {am+bn} over all possible paths
• Chamfer distance is metric if a, b > 0
• If b > 2a, then diagonal moves are ignored
• Special cases:
– a=1, b=infinity (Manhattan)
– a=1, b=1 (chessboard)
– a=1, b=sqrt(2) (another reasonable choice)
– a=1, b=1.351 (best approximation to Euclidean)
– a=3, b=4 (best integer approximation, scaled by factor of 3)
[G. Borgefors, Distance transformations in digital images, CVGIP, 1986]
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Chamfering (cont.)
• Chamfering is process of computing distance to
each foreground pixel
• Two-pass algorithm
– Traverse top-to-bottom, left-to-right
– Traverse bottom-to-top, right-to-left
In each case, compute minimum distance foreground pixels
L: R: L: R:
4-connectivity 8-connectivity
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Chamfering (cont.)
• Algorithm (for D4 using Manhattan distance):
Function labels = Chamfer(image)
// first pass
for y=0 to height-1,
for x=0 to width-1,
d(x,y) = image(x,y) ? 0
: min(infinity, 1+d(x-1,y), 1+d(x,y-1))
// second pass
for y=height-1 to 0 step -1,
for x=width-1 to 0 step -1,
d(x,y) = image(x,y) ? 0
: min(d(x,y), 1+d(x+1,y), 1+d(x,y+1))
Note:
“? :” means “if-else”
(C conditional
expression operator)
• Shape matching
http://www.gavrila.net/Research/Chamfer_System/chamfer_system.html
• Labeling regions
(floodfill, connected components)
• Region properties
(area and boundary properties)
• Region
}
– Euler number
– convex hull
– skeleton We will focus
– moments
– compactness
on regions
– eccentricity (elongatedness)
• Boundary
– chain code
– signature
– r-q plot
– s-y plot
– boundary segments
– shape number
– Fourier descriptors
E = C- H
components holes
• Or, equivalently,
– where wavefronts (grassfires) meet (shock graph)
– centers of maximal balls
centroid
• What are ?
(area, 0, variance, skew, kurtosis)
(area)
(variance in x)
(variance in y)
Central moments
(and normalized / Hu)
are computed without
touching the pixels again!
Alternative: Use
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Eccentricity
• Approximate region with ellipse
• eccentricity = a / a =
• Formula given by PCA
Goals:
1. fit ellipsoid to data
2. reduce dimensionality
Ellipsoid specified by
• center
(given by mean of data)
• orientation of axes
(given by eigenvectors of covariance matrix of
data)
• length of axes
(given by square root of eigenvalues of covariance
matrix of data)
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
PCA (cont.)
• n points in d dimensional • eigenvalues and
space eigenvectors
• matrix form
• mean
C = (1/9) * [ 12 -10]
[-10 12]
e1 e2 l1
C = PLPT = [-0.7 0.7] [2.4 0 ] [-0.7 0.7]
[ 0.7 0.7] [ 0 0.2] [ 0.7 0.7]
l2
major axis = e1√l1 = [1.1 -1.1]T
• Eigenvalues
solve det(C-lI)=0)
• Eccentricity
ranges from
0 (circle) to 1 (line)
• Eigenvectors
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Eigenfaces
mean face
eigenvectors
N x N image is a point in an N2 dimensional space
N2 x N2 Covariance matrix captures relationships
between face images in ensemble
Turk and Pentland, 1991
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847
Fruit classification
mij mij
(moments)
fruit1.pgm fruit2.pgm
S. Birchfield, Clemson Univ., ECE 847, http://www.ces.clemson.edu/~stb/ece847