Download presentation
Presentation is loading. Please wait.
Published byBerniece Little Modified over 9 years ago
2
Lecture 06 Binary Image Analysis Lecture 06 Binary Image Analysis Mata kuliah: T0283 - Computer Vision Tahun: 2010
3
January 20, 2010T0283 - Computer Vision3 Learning Objectives After carefullylistening this lecture, students will be able to do the following : After carefully listening this lecture, students will be able to do the following : show how connected component labeling is performed and its uses in shape classifier show how connected component labeling is performed and its uses in shape classifier demonstrate object area and perimeter calculation based on binary images demonstrate object area and perimeter calculation based on binary images
4
January 20, 2010T0283 - Computer Vision4 From Processing to Analysis Holistic perspective in binary image analysis PHIL High-level vision Low-level vision Localized perspective in binary image processing
5
January 20, 2010T0283 - Computer Vision5 Connectivity 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
6
January 20, 2010T0283 - Computer Vision6 Connected Components in Digital Images 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 contains exclusively of pixels in S. Two types of connectivity: 4 - (edge) connectivity and 8- (vertex) connectivity
7
January 20, 2010T0283 - Computer Vision7 Connected Component Two pixels are c-adjacent (c=4 or 8) if they share at least an edge (c=4), or a vertex (c=8). Two pixels are c-connected (c=4 or 8) if it is possible to find a path between these two pixels through pairs of c-adjacent (c=4,8) pixels. A c-connected component is a maximal connected set where each pixel is c-connected to other pixels in the set.
8
January 20, 2010T0283 - Computer Vision8 Example p q p ~ q no matter 4-neighbors or 8-neighbors p q p ~ q only when 8-neighbors is considered
9
January 20, 2010T0283 - Computer Vision9 Component Labeling If 4-neighbors, three connected components If 8-neighbors, two connected components original binary image
10
January 20, 2010T0283 - Computer Vision10 Connected Component Labeling 1 23 45
11
January 20, 2010T0283 - Computer Vision11 MATLAB 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.
12
January 20, 2010T0283 - Computer Vision12 Euler Number Euler Number EN=number of connected components – number of holes EN=-3 EN=0 EN=-1
13
January 20, 2010T0283 - Computer Vision13 CC Algorithm Process the image row by row Assign a label to the first pixel of each CC Otherwise assign its label by propagating from left or top Clash! (equivalence) ?111 211 2121
14
January 20, 2010T0283 - Computer Vision14 One approach Propagate the smaller label in case of clash Record the equivalence in a table After the entire image is processed, find the set of equivalence classes Second pass replaces each label with its equivalent class Two passes!
15
January 20, 2010T0283 - Computer Vision15 Boundary of Binary Objects XX X X=X-(X B) _ X=(X B) – B + or
16
January 20, 2010T0283 - Computer Vision16 Chain Codes Boundary Representation 4-directional chain code: 0033333323221211101101 8-directional chain code: 076666553321212
17
January 20, 2010T0283 - Computer Vision17 Two Problems with the Chain Code Chain code representation is conceptually appealing, yet has the following two problems Dependent on the starting point Dependent on the orientation To use boundary representation in object recognition, we need to achieve invariance to starting point and orientation Normalized codes Differential codes
18
January 20, 2010T0283 - Computer Vision18 Normalization Strategy 33001122 30011223 00112233 01122330 11223300 12233001 22330011 23300112 Sort rows 00112233 01122330 11223300 12233001 22330011 23300112 33001122 30011223 00112233 First row gives the normalized chain code
19
January 20, 2010T0283 - Computer Vision19 Differential Strategy 33001212 33010122 00121233 01012233 Differential coding: d k =c k -c k-1 (mod 4) for 4-directional chain codes d k =c k -c k-1 (mod 8) for 8-directional chain codes normalize 90 o
20
January 20, 2010T0283 - Computer Vision20 Shape Numbers= Normalized Differential Chain Codes Differential code: d k =c k -c k-1 (mod 4) 33001212 10101131 33010122 10113110 01011311 differentiate normalize differentiate normalize Note that the shape numbers of two objects related by 90 o rotation are indeed identical
21
January 20, 2010T0283 - Computer Vision21 Examples : Chain Encoding x y Encoding start point 1 unit pixel 2 unit pixel
22
January 20, 2010T0283 - Computer Vision22 PDirection 0 6 5 4 3 2 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 = S E + V2 S O units = 16 + 4 V2 = 21.66 units Perimeter Calculation
23
January 20, 2010T0283 - Computer Vision23 Y Direction 0 Additive comp. = 1 x y Y Direction 5 Subtractive comp = (1 x y) – 0.5 Y Direction 1 Subtrac. comp. = (1 x y) + 0.5 Direction 2 dan 6 Zero component (neutral) Area Calculation Y
24
January 20, 2010T0283 - Computer Vision24 P 0 6 5 4 3 2 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 66 7 3 4 2 3 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)
25
January 20, 2010T0283 - Computer Vision25 MATLAB Implementation
26
January 20, 2010T0283 - Computer Vision26 Segmen citra biner 00000000 00# # #0#0 00####00 00###0#0 00 0 00##0 00000000 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)
27
January 20, 2010T0283 - Computer Vision27 Segmen citra biner 00000000 00# # #0#0 00####00 00###0#0 00 0 00##0 00000000 Chord Encoding 1 (2,4) (6,6); 2 (2,5); 3 (2,4) (6,6); 4 (5,6). baris kolom
28
January 20, 2010T0283 - Computer Vision28 Matlab Implementation on Shapes Classifier Step 1: Read image Step 2: Convert image from rgb to gray Step 3: Threshold the image Step 4: Invert the Binary Image Step 5: Find the boundaries Concentrate Step 6: Determine Shapes properties Step 7: Classify Shapes according to
29
January 20, 2010T0283 - Computer Vision29 Step 1: Read image RGB = imread('test.bmp'); figure, imshow(RGB), title('INPUT IMAGE');
30
January 20, 2010T0283 - Computer Vision30 Step 2: Convert image from rgb to gray GRAY = rgb2gray(RGB); figure,imshow(GRAY),title('GRAY IMAGE');
31
January 20, 2010T0283 - Computer Vision31 Step 3: Threshold the image. threshold = graythresh(GRAY); BW = im2bw(GRAY, threshold); figure, imshow(BW), title('BINARY IMAGE');
32
January 20, 2010T0283 - Computer Vision32 Step 4: Invert the Binary Image BW = ~ BW; figure,imshow(BW),title('INVERTED BINARY IMAGE');
33
January 20, 2010T0283 - Computer Vision33 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 properties STATS = regionprops(L, 'all'); % we need 'BoundingBox' and 'Extent'
34
January 20, 2010T0283 - Computer Vision34 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'); end
35
January 20, 2010T0283 - Computer Vision35 Step 7: Classify Shapes according to properties (cont’d) figure, imshow(RGB), title('HASIL IDENTIFIKASI SQUARE, CIRCLE & RECTANGLE'); hold on
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.