lecture 06 binary image analysis lecture 06 binary image analysis mata kuliah: t0283 - computer...
TRANSCRIPT
Lecture 06Lecture 06 Binary Image AnalysisBinary Image Analysis
Mata kuliah : T0283 - Computer VisionTahun : 2010
January 20, 2010 T0283 - Computer Vision 3
Learning ObjectivesLearning Objectives
After carefullyAfter carefully listening this lecture, students will listening this lecture, students will be able to do the following :be able to do the following :
show how connected component labeling is show how connected component labeling is performed performed and its uses in shape classifierand its uses in shape classifier
demonstrate object area and perimeter demonstrate object area and perimeter calculation based calculation based on binary imageson binary images
January 20, 2010 T0283 - Computer Vision 4
From Processing to AnalysisFrom Processing to Analysis
Holistic perspective in binary image analysis
PHILHigh-level vision
Low-level vision
Localized perspective in binary image processing
January 20, 2010 T0283 - Computer Vision 5
ConnectivityConnectivity
X
Y
X’
Y’
X and Y are connected X’ and Y’ are NOT connected
a and b are connected if there exists a path from a to b
Notation: if a and b are connected, we write a ~ b
January 20, 2010 T0283 - Computer Vision 6
Connected Components in Digital Connected Components in Digital ImagesImages
A set S of pixels is a CC if there is at least one path A set S of pixels is a CC if there is at least one path that joins every pair {p,q} of pixels in S, and that joins every pair {p,q} of pixels in S, and contains exclusively of pixels in S.contains exclusively of pixels in S.
Two types of connectivity: 4 - (edge) connectivity Two types of connectivity: 4 - (edge) connectivity and 8- (vertex) connectivityand 8- (vertex) connectivity
January 20, 2010 T0283 - Computer Vision 7
Connected ComponentConnected Component
Two pixels are Two pixels are c-adjacentc-adjacent (c=4 or 8) if they share at (c=4 or 8) if they share at least an edge (c=4), or a vertex (c=8).least an edge (c=4), or a vertex (c=8).Two pixels are Two pixels are c-connectedc-connected (c=4 or 8) if it is possible (c=4 or 8) if it is possible to find a path between these two pixels through to find a path between these two pixels through pairs of c-adjacent (c=4,8) pixels.pairs of c-adjacent (c=4,8) pixels.A A c-connected componentc-connected component is a maximal connected is a maximal connected set where each pixel is c-connected to other pixels in set where each pixel is c-connected to other pixels in the set.the set.
January 20, 2010 T0283 - Computer Vision 8
ExampleExample
p
q
p ~ q no matter 4-neighbors p ~ q no matter 4-neighbors or 8-neighborsor 8-neighbors
p
q
p ~ q only when 8-neighborsp ~ q only when 8-neighborsis consideredis considered
January 20, 2010 T0283 - Computer Vision 9
Component LabelingComponent Labeling
If 4-neighbors,three connectedcomponents
If 8-neighbors,two connectedcomponents
originalbinaryimage
January 20, 2010 T0283 - Computer Vision 10
Connected Component LabelingConnected Component Labeling
1
2 3
4 5
January 20, 2010 T0283 - Computer Vision 11
MATLAB Function BWLABELMATLAB Function BWLABEL
>help bwlabel BWLABEL Label connected components in binary image.
L = BWLABEL(BW,N) returns a matrix L, of the same size as BW, containing labels for the connected components in BW. N can have a value of either 4 or 8, where 4 specifies 4-connected objects and 8 specifies 8-connected objects; if the argument is omitted, it 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 also bwareaopen, bweuler, bwlabeln, bwselect, label2rgb.
January 20, 2010 T0283 - Computer Vision 12
Euler NumberEuler Number
Euler Number EN=number of connected components – number of holes
EN=-3
EN=0 EN=-1
January 20, 2010 T0283 - Computer Vision 13
CC AlgorithmCC Algorithm
Process the image row by rowProcess the image row by rowAssign a label to the first pixel of each CCAssign a label to the first pixel of each CCOtherwise assign its label by propagating from left or Otherwise assign its label by propagating from left or toptop
Clash! (equivalence)??111111
221111
2211
2211
January 20, 2010 T0283 - Computer Vision 14
One approachOne approach
Propagate the smaller label in case of clashPropagate the smaller label in case of clashRecord the equivalence in a tableRecord the equivalence in a tableAfter the entire image is processed, find the set After the entire image is processed, find the set of equivalence classesof equivalence classesSecond pass replaces each label with its Second pass replaces each label with its equivalent classequivalent class
Two passes!Two passes!
January 20, 2010 T0283 - Computer Vision 15
Boundary of Binary ObjectsBoundary of Binary Objects
XX
X=X-(X B)_ X=(X B) – B+or
January 20, 2010 T0283 - Computer Vision 16
Chain Codes Boundary RepresentationChain Codes Boundary Representation
4-directional chain code: 0033333323221211101101
8-directional chain code: 076666553321212
January 20, 2010 T0283 - Computer Vision 17
Two Problems with the Chain CodeTwo Problems with the Chain Code
Chain code representation is conceptually Chain code representation is conceptually appealing, yet has the following two appealing, yet has the following two problemsproblems
Dependent on the starting pointDependent on the starting point
Dependent on the orientationDependent on the orientation
To use boundary representation in object To use boundary representation in object recognition, we need to achieve invariance recognition, we need to achieve invariance to starting point and orientationto starting point and orientation
Normalized codesNormalized codes
Differential codesDifferential codes
January 20, 2010 T0283 - Computer Vision 18
Normalization StrategyNormalization Strategy
33001122
3300112230011223001122330112233011223300122330012233001123300112
Sortrows
0011223301122330112233001223300122330011233001123300112230011223
00112233
First row gives the normalized chain code
January 20, 2010 T0283 - Computer Vision 19
Differential StrategyDifferential Strategy
33001212 33010122
00121233 01012233
Differential coding:
dk=ck-ck-1 (mod 4) for 4-directional chain codes
dk=ck-ck-1 (mod 8) for 8-directional chain codes
normalize normalize
90o
January 20, 2010 T0283 - Computer Vision 20
Shape Numbers= Normalized Shape Numbers= Normalized Differential Chain CodesDifferential Chain Codes
Differential code: dk=ck-ck-1 (mod 4)
33001212
10101131
33010122
10113110
01011311 01011311
differentiate
normalize
differentiate
normalize
Note that the shape numbers of two objects related by 90o rotationare indeed identical
January 20, 2010 T0283 - Computer Vision 21
Examples : Chain Encoding
x
yEncoding
start point
1 unit pixel
2 unit pixel
January 20, 2010 T0283 - Computer Vision 22
P Direction 0
65
4
32
1
7
1 1 0 0 0 0 6 0 6 6 6 4 6 4 4 4 4 3 3 2
Start
Perimeter P = SE + V2 SO units
= 16 + 4 V2 = 21.66 units
Perimeter Calculation
January 20, 2010 T0283 - Computer Vision 23
Y
Direction 0Additive comp. = 1 x y
Y
Direction 5Subtractive comp = (1 x y) – 0.5
Y
Direction 1Subtrac. comp. = (1 x y) + 0.5
Direction 2 dan 6Zero component (neutral)
Area Calculation
Y
January 20, 2010 T0283 - Computer Vision 24
P 0
65
4
32
1
7
1 1 0 0 0 0 6 0 6 6 6 4 6 4 4 4 4 3 3 2
Start
AdditiveSubtractive
5
667
34
23
5
4
y-coordinate
Area = 5.5 + 6.5 + 7 + 7 + 7 + 7 + 0 + 6 + 0 + 0 + 0 – 3 + 0 – 2 – 2 – 2 – 2 – 2.5 – 3.5 + 0 = 29 square units
Area Calculation (cont’d)
January 20, 2010 T0283 - Computer Vision 25
MATLAB ImplementationMATLAB Implementation
January 20, 2010 T0283 - Computer Vision 26
Segmen citra biner
0 0 0 0 0 0 0 0
0 0 # # # 0 # 0
0 0 # # # # 0 0
0 0 # # # 0 # 0
0 0 0 0 0 # # 0
0 0 0 0 0 0 0 0
Run Length Encoding (RLE)
10(0), 3(1), 1(0), 1(1), 3(0), 4(1), 4(0), 3(1), 1(0), 1(1), 6(0), 2(1), 9(0)
January 20, 2010 T0283 - Computer Vision 27
Segmen citra biner
0 0 0 0 0 0 0 0
0 0 # # # 0 # 0
0 0 # # # # 0 0
0 0 # # # 0 # 0
0 0 0 0 0 # # 0
0 0 0 0 0 0 0 0
Chord Encoding
1 (2,4) (6,6); 2 (2,5); 3 (2,4) (6,6); 4 (5,6).
bariskolom
January 20, 2010 T0283 - Computer Vision 28
Matlab Implementation on Shapes Matlab Implementation on Shapes ClassifierClassifier
Step 1: Read image Step 1: Read image
Step 2: Convert image from rgb to grayStep 2: Convert image from rgb to gray
Step 3: Threshold the imageStep 3: Threshold the image
Step 4: Invert the Binary ImageStep 4: Invert the Binary Image
Step 5: Find the boundaries ConcentrateStep 5: Find the boundaries Concentrate
Step 6: Determine Shapes propertiesStep 6: Determine Shapes properties
Step 7: Classify Shapes according toStep 7: Classify Shapes according to
January 20, 2010 T0283 - Computer Vision 29
Step 1: Read image
RGB = imread('test.bmp');RGB = imread('test.bmp');figure, imshow(RGB), title('INPUT figure, imshow(RGB), title('INPUT IMAGE');IMAGE');
January 20, 2010 T0283 - Computer Vision 30
Step 2: Convert image from rgb to grayStep 2: Convert image from rgb to gray
GRAY = rgb2gray(RGB);figure,imshow(GRAY),title('GRAY IMAGE');
January 20, 2010 T0283 - Computer Vision 31
Step 3: Threshold the image. Step 3: Threshold the image.
threshold = graythresh(GRAY);threshold = graythresh(GRAY);BW = im2bw(GRAY, threshold);BW = im2bw(GRAY, threshold);figure, imshow(BW), title('BINARY IMAGE');figure, imshow(BW), title('BINARY IMAGE');
January 20, 2010 T0283 - Computer Vision 32
Step 4: Invert the Binary ImageStep 4: Invert the Binary Image
BW = ~ BW;figure,imshow(BW),title('INVERTED BINARY IMAGE');
January 20, 2010 T0283 - Computer Vision 33
Step 5: Find the boundaries
Concentrate only on the exterior boundaries.Option 'noholes' will accelerate the processing by preventing bwboundaries from searching for inner contours.
[B,L] = bwboundaries(BW, 'noholes');%[L, N] = bwlabel(BW,8);
Step 6: Determine objects propertiesSTATS = regionprops(L, 'all'); % we need 'BoundingBox' and 'Extent'
January 20, 2010 T0283 - Computer Vision 34
Step 7: Classify Shapes according to properties
% Square = 3 = (1 + 2) = (X=Y + Extent = 1)% Rectangular = 2 = (0 + 2) = (only Extent = 1)% Circle = 1 = (1 + 0) = (X=Y , Extent < 1)% UNKNOWN = 0
for i = 1 : length(STATS) W(i) = uint8(abs(STATS(i).BoundingBox(3) - STATS(i).BoundingBox(4)) < 0.1); W(i) = W(i) + 2 * uint8((STATS(i).Extent - 1) == 0 ); centroid = STATS(i).Centroid; switch W(i) case 1 plot(centroid(1),centroid(2),'wO'); case 2 plot(centroid(1),centroid(2),'wX'); case 3 plot(centroid(1),centroid(2),'wS'); endend
January 20, 2010 T0283 - Computer Vision 35
Step 7: Classify Shapes according to properties (cont’d)
figure, imshow(RGB), title('HASIL IDENTIFIKASI SQUARE, CIRCLE & RECTANGLE'); hold on