IMAGE SEGMENTATION – CONNECTED COMPONENT LABELING Segmentation can be viewed as a process of pixel classification; the image is segmented into objects or regions by assigning individual pixels to classes. Connected Component Labeling assigns pixels to specific classes by verifying if an adjoining pixel (i.e., neighboring pixel) already belongs to that class. There are two “standard” definitions of pixel connectivity: 4 neighbor connectivity and 8 neighbor connectivity.
IMAGE SEGMENTATION – CONNECTED COMPONENT LABELING 4 Neighbor Connectivity 8 Neighbor Connectivity Pi,j Pi,j
CONNECTED COMPONENT LABELING: FIRST PASS EQUIVALENCE: B=C A A A B B C C B B B C C B B B B B B
CONNECTED COMPONENT LABELING: SECOND PASS TWO OBJECTS! A A A B B C B B C B B B B C B C B B B B B B
CONNECTED COMPONENT LABELING: EXAMPLE (DEMO)
CONNECTED COMPONENT LABELING: TABLE OF EQUIVALENCES 2 = 5 16 27 50 81 112 127 9 28 39 86 134 34 51 137 10 37 87 138 46 111 66 113 12 40 41 72 119 120 18 76 23 122
CONNECTED COMPONENT LABELING: TABLE OF EQUIVALENCES 2 = 5 37 86 111 138 9 39 87 10 40 41 112 12 46 113 16 50 119 18 51 120 23 66 122 27 72 127 28 76 134 34 81 137
Basic Connected Component Labeling Binary Image with Background=0, Objects=1 x = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0
Basic Connected Component Labeling Binary Image with Background=0, Objects=1 x(1,:)=0; x(:,1)=0; imshow(x,[0 1]); K=1; cnt=2; for J=2:H for I=2:W if x(J,I)==1 %% Object found if (x(J-1,I)==0 && x(J,I-1)==0) x(J,I)=cnt; %% New Object cnt=cnt+1; else if x(J-1,I)~=0 x(J,I)=x(J-1,I); if (x(J,I-1)~=0) && (x(J,I-1)~=x(J-1,I)) eq(K,1)=x(J-1,I); eq(K,2)=x(J,I-1); K=K+1; end; x(J,I)=x(J,I-1); end
Basic Connected Component Labeling eq = 2 3 3 4 4 5 5 6 6 7 7 8 8 9 Basic Connected Component Labeling First Pass x = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 3 2 0 0 0 0 0 0 0 4 3 2 0 0 0 0 0 0 5 4 3 2 0 0 0 0 0 6 5 4 3 2 0 0 0 0 7 6 5 4 3 2 0 0 0 8 7 6 5 4 3 2 0 0 9 8 7 6 5 4 3 2 0
Connected Component Labeling with Line Correction Binary Image with Background=0, Objects=1 x = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0
Connected Component Labeling with Line Correction Binary Image with Background=0, Objects=1 if (x(J-1,I)==0 && x(J,I-1)==0) x(J,I)=cnt; %% New Object cnt=cnt+1; S=I; else if x(J-1,I)~=0 x(J,I)=x(J-1,I); if (x(J,I-1)~=0) && (x(J,I-1)~=x(J-1,I)) if S>0 for R=I:-1:S x(J,R)=x(J-1,I); end; S=0; cnt=cnt-1; eq(K,1)=x(J-1,I); eq(K,2)=x(J,I-1); K=K+1; end x(J,I)=x(J,I-1); x(1,:)=0; x(:,1)=0; imshow(x,[0 1]); K=1; cnt=2; for J=2:H S=0; for I=2:W if x(J,I)==1 %% Object found
Connected Component Labeling with Line Correction First Pass x = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 2 2 2 0 0 0 0 0 0 2 2 2 2 0 0 0 0 0 2 2 2 2 2 0 0 0 0 2 2 2 2 2 2 0 0 0 2 2 2 2 2 2 2 0 0 2 2 2 2 2 2 2 2 0
Basic Connected Component Labeling Binary Image with Background=0, Objects=1 x = 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0
Basic Connected Component Labeling First Pass x = 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 3 3 0 0 0 0 2 2 2 2 3 3 0 0 4 4 2 2 2 2 3 3 0 eq = 3 2 2 4
Connected Component Labeling with Line Correction Binary Image with Background=0, Objects=1 x = 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0
Connected Component Labeling with Line Correction First Pass x = 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 3 3 0 0 0 0 2 2 2 2 3 3 0 0 2 2 2 2 2 2 3 3 0 eq = 3 2