Chapter 3 Binary Image Analysis - ULisboa · Dilation and erosion – Generalization for...
-
Upload
hoangtuyen -
Category
Documents
-
view
235 -
download
0
Transcript of Chapter 3 Binary Image Analysis - ULisboa · Dilation and erosion – Generalization for...
Chapter 3 – Binary Image Analysis
Comunicação Visual Interactiva
Pixels and Neighborhoods
Vizinhança N4
• Most common neighborhoods
• Use of masks
– Example:
Vizinhança N8
origem
input output
CVI - Binary Image Analysis 2
Example
input saída
0 1 0
1 0 1
0 1 0
80 160 200 240 160
120 200 280 320 240
120 200 280 320 240
120 200 280 320 240
80 160 200 240 160
output
0 0 0
0 1 0
0 0 0
and with the mask ?
CVI - Binary Image Analysis 3
Counting objects
• Algorithm
– Hypothesis: An object is a set of connected pixels (connectivity 4) and
without inner holes
Outer corners Inner corners
CVI - Binary Image Analysis 4
How many objects?
e - 21
i - 5
44
16
4
521#
e
i
e
e e
e
e e
e
e e
e
e
e
e e
e
i
i
e
i
e
e
i
e
e
CVI - Binary Image Analysis 5
And now?
e
i
e
e
e
e e
e
e e
e
e
e
e e
e
i
i
e
i
e
e
i
e
e
e
e e
e - 23
i - 4
?4
19
4
423#
CVI - Binary Image Analysis 6
Connected Component Analysis – recursive algorithm
input
output
CVI - Binary Image Analysis 7
Recursive algorithm - Example
Neighbor 4
Neighbor 8
CVI - Binary Image Analysis 8
Union-Find structure
CVI - Binary Image Analysis 9
Classic CCA using Union-Find
input
1º step
2º step
equiv. classes
CVI - Binary Image Analysis 10
Exercise
• Apply the CCA algorithm considering connectivity 4
• What would be the result considering connectivity 8?
1 2
1 1 1 1
1
0
2
0 0
3
1 1
1 1
3 3
4
1
3
3 3
3
1
5 4
0
4
0
5
4
CVI - Binary Image Analysis 11
Morphological operators
• Structuring elements
– We need to define the center (i.e. origin)
• Definition: A dilation of the binary image B by the structuring
element S is defined as
• Definition: A erosion of the binary image B by the structuring
element S is defined as
Bb
bSSB
SsBsbbSB
ones(3,5) disk(5) ring(5)
SsbsSb
CVI - Binary Image Analysis 12
Morphological operations - Examples
CVI - Binary Image Analysis 13
Dilation and erosion – Generalization for monochromatic images
Operação Rule
Dilation
The output pixel value is the maximum value of all
pixels in the neighborhood of the input pixel. It is
assigned minimum value (0) to the other pixels
Erosion
The output pixel value is the minimum value of all
pixels in the neighborhood of the input pixel. It is
assigned a maximum value (1 or 255) to the other pixels
Dilation of the binary image Dilation of a monochromatic image
CVI - Binary Image Analysis 14
Morphological operations
• Definition: The closing of binary imge B by the structuring
element S is defined by
• Definition: A opening of a binary image B by the structuring
element S is defined by
SSBSB
SSBSB
B
S
SB
SB SB
SB
CVI - Binary Image Analysis 15
• Medical applications (image resolution of 512x512)
– opening with disk (13) folowed by closing with disk (2)
• Extraction of shape primitives
– Subtraction between the original image and the image obtained with the
opening operator (using a disck as the structuring element)
Examples of morphology to extract shape primitives
original binarized processed
CVI - Binary Image Analysis 16
original opening corners
Inspection procedure
input
output
a) b)
c) d)
e) f)
CVI - Binary Image Analysis 17
Conditional Dilation
• Definition: Given two binary images, original B, and processed
C, and the structuring element S, and let
The conditional dilation of C by S with respect to B is defined by
BSCCCC nn 10 e
mB CSC
where m is the smallest integer satisfying 1 mm CC
B
V
VBC SC B
S
CVI - Binary Image Analysis 18
Region properties
• Area
• Centroid
• Perimeter pixels
– Perimeter length
• Circularity (1)
Rcr
A),(
1
Rcr
Arr
),(
1
Rcr
Acc
),(
1
RcrNRcrP ),(),( 84
RcrNRcrP ),(),( 48
),(),(),(2
),(),(
4811
411
kkkkkk
kkkk
crNcrNcrk
crNcrkP
A
PC
2
1
CVI - Binary Image Analysis 19
Properties (cont.)
• Circularity (2)
– Mean radial distance
– Standard deviation of radial distance
R
RC
2
1
0
),(),(1 K
k
kkR crcrK
2
11
0
2),(),(
1
K
k
RkkR crcrK
CVI - Binary Image Analysis 20
Properties – lengths and boundaries
• Rectangle (and octagon) bounding box
• Axis length
º45:
º45:)(
)sin(1
)cos(1
Q
QccrrD 2
12
2
1222D
21
2D
º0 º45
CVI - Binary Image Analysis 21
Properties– 2nd order moments
• Second order moments
• Relation between moments and elliptic regions
• Axis with least second order moment
– Formulation
– Solution
ccrr
rc
2ˆ2tan
12|, 22 fcercdrcrR
rrrc
rccc
rcccrrfe
ed
24
1
Rcr
Acc cc),(
21
Rcr
Arr rr),(
21
Rcr
Arc ccrr),(
1
RcrA
RcrAcr
V
d
),(
21
),(
21,,
sin,cos
2/
CVI - Binary Image Analysis 22
Region Adjacency Graphs
• Problem: regions that have inner holes (in the background)
• Solution: algorithm with 3 steps
– Aplication of the CCA algorithm twice: (1) foreground pixels and (2)
background pixels
– (3) Building of graph relations
CVI - Binary Image Analysis 23
Limiar Threshold
• Definition: the histogram h of a monochromatic image I is
defined by mcrIcrmh ),(),()(
CVI - Binary Image Analysis 24
CVI - Análise de Imagens Binárias
Automatic computation of the Threshold
• Otsu Method
– Let us assume that we have an image , with and
denotes the gray level intensity in the coordinates .
– Also, assume that represents the gray levels in the
image .
– Defining as the nº of pixels at a given level , the total nº of the
pixels in the image is given by
– We can compute the weights of the pixels at the level as
– We are going to assume that we have two classes of gray levels,
using a threshold
RI :
),( yxI ),( yx
MaxValM ,...,3,2,1
I
2R
in Mi
MaxVal
i
inn1
mC ,...,2,11 MaxValmmC ,...,2,12 m
i
nniP i /)(
25 CVI - Binary Image Analysis
Automatic computation of the Threshold
• Otsu Method
– Ideia: intra-class minimization variance
– The weights allow to compute the mean of the gray levels of the two
classes;
– Now, we can compute the variances, from the above means:
)()()()( 2
22
2
11
2 mmmmW
)()(1
1 iPmwm
i
MaxVal
mi
iPmw1
2 )()(
m
i
mwiiPm1
11 )(/)()(
MaxVal
mi
mwiiPm1
22 )(/)()(
m
ii
mwiPmim )(/)()()( 1
2
1
2
1
MaxVal
mi
mwiPmim1
2
2
2
2
2 )(/)()()(
CVI - Binary Image Analysis 26
Cálculo automático do limiar
• Otsu then proposes the following “goodness” of the threshold
where
22111
2 )()()(1)( mmmwmwB
22 / WB
22121 )()()()( mmmwmw
)(1)( 12 mwmw
2
22
2
11
2 wwW
CVI - Binary Image Analysis 27
2
W
2
B
- within class (intra-class) variance
- between class (inter-class) variance
Recursive Algorithm
• Synopsis of the Otsu algorithm to find the threshold t
– Initializaion
– For m := 0 to MaxVal
– Limiar computation
)1()()1( 11 mPmwmw
)0()0(1 Pw
)1(
)1()1()()()1(
1
111
mw
mPmmmwm
)1(1
)1()1()1(
1
112
mw
mmwm
0)0(1
22111
2 )()()(1)()( mmmwmwmB
MaxVal
i
iiP0
)(
CRihiP /)()(
)(maxarg 2 mm Bm
t = 93
Original (MaxVal=255)
CVI - Binary Image Analysis 28
1 Compute histogram and probabilities of each intensity level
2 Set up initial \omega_i(0) and \mu_i(0)
3 Step through all possible thresholds t = 1 … maximum intensity
3.1 Update \omega_i and \mu_i
3.2 Compute \sigma^2_b(t)
4 Desired threshold corresponds to the maximum \sigma^2_b(t)
CVI - Binary Image Analysis 29