11.07.2015 Views

Binary Vision

Binary Vision

Binary Vision

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5 <strong>Binary</strong> <strong>Vision</strong>5.1 <strong>Binary</strong> ImageA binary image can be obtained from a grayscaleor color image by selecting a subset of thepixels as foreground pixels and leaving the restas background pixels


Thresholding based on histogramCompute Histogram H of gray-level image Iprocedure histogram (I,H) {“Initialize all bins to zero”for i:=0 to MaxValH[i]:=0;“Compute values”for L:=0 to MaxRowfor P:=0 to MaxCol {grayval:= I[L,P];H[grayval]:= H[grayval] + 1;}}


5.2 MaskApplying a mask to an image is a basic concept in imageprocessing – convolution.(1) What is a mask: A mask is a set of pixel positions withvalues called weights. A 3x3 mask is as follows.w1 w2 w3w4 w5 w6w7 w8 w91 w2 w31 1 1111w4 w5 w61 1 1w7 w8 w91 w2 w31 2 1242w4 w5 w61 2 1w7 w8 w9


(2) How to use a mask:For any point (x,y) in the image, align the centerof the mask to it. We havefnew( x,y)=9∑ wi=1iziz1 z 2 z3w1 w2 w3z 4 z5 z 6w4 w5 w6z 7 z8 z9w7 w8 w9(x,y)


5.3 Counting objectsApplications: E.g., count cells in biology, particles in materialsparticles in metal cells in biology


5.3 Counting objects -- method 1Method 1:0 00 01 00 10 11 00 00 0E Masks (1 – foreground, 0 – background)for detecting external corners1 11 10 11 01 00 11 11 1I Masks (1 – foreground, 0 – background)for detecting internal corners


5.3 Counting objects -- method 1Compute the number of foreground objects in binary image BCount_objects (B) {E := 0;I := 0;for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1 {if external_match (L,P) then E := E + 1;if internal_match (L,P) then I := I + 1;}return ((E-I)/4);}


5.3 Counting objects -- method 1Limitations:• must be 4-connected foregrounds• no interior holes


5.3 Counting objects -- method 2Connected Components Labelling:A connected components labeling of abinary image is a labeled image in which thevalue of each pixel is the label of itsconnected componentsExample =>


5.3 Counting objects -- method 2


5.3 Counting objects -- method 2A Recursive Labelling Algorithm:Recursive_connected_components (B, LB) {LB := negate (B);Label := 0;Find_components (LB, label);Print (LB);}Find_components (LB, label) {for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {label := label + 1;search (LB, label, L P);}}


5.3 Counting objects -- method 2A Recursive Labelling Algorithm:Find_components (LB, label) {for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {label := label + 1;search (LB, label, L, P);}}21x434-neighborhood1 2 34 x 5search (LB, label, L, P) {LB[L,P] := label;6 7 8Nset := neighbors (L, P);For each [L’, P’] in Nset {8-neighborhoodIf LB[L’, P’] == -1 then search (LB, label, L’, P’);}}


5.3 Counting objects -- method 2Recursive_connected_components (B, LB) {LB := negate (B);Label := 0;Find_components (LB, label);Print (LB);}Find_components (LB, label) {for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {label := label + 1;search (LB, label, L, P);}}search (LB, label, L, P) {LB[L,P] := label;Nset := neighbors (L, P);For each [L’, P’] in Nset {If LB[L’, P’] == -1 then search (LB, label, L’, P’);}}1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 1 1 1 0 0 00 0 0 0 0 1 0 1 0 1 10 0 0 0 0 1 0 1 0 0 00 0 1 1 0 1 1 1 0 0 00 1 0 1 0 1 0 1 0 0 00 0 0 1 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 1 0


5.3 Counting objects -- method 2Recursive_connected_components (B, LB) {LB := negate (B);Label := 0;Find_components (LB, label);Print (LB);}-1 0 0 0 0 0 0 0 0 0 0-1 -1 0 0 0 -1 -1 -1 0 0 0Find_components (LB, label) {0 0 0 0 0 -1 0 -1 0 -1 -1for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 10 0 0 0 0 -1 0 -1 0 0 0if LB[L,P] == -1 then {label := label + 1;0 0 -1 -1 0 -1 -1 -1 0 0 0search (LB, label, L, P);}}search (LB, label, L, P) {LB[L,P] := label;Nset := neighbors (L, P);For each [L’, P’] in Nset {000-100000-1-10000-100000-10000000-1000If LB[L’, P’] == -1 then search (LB, label, L’, P’);}}


5.3 Counting objects -- method 2Recursive_connected_components (B, LB) {LB := negate (B);Label := 0;Find_components (LB, label);Print (LB);}1 0 0 0 0 0 0 0 0 0 0-1 -1 0 0 0 -1 -1 -1 0 0 0Find_components (LB, label) {0 0 0 0 0 -1 0 -1 0 -1 -1for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 10 0 0 0 0 -1 0 -1 0 0 0if LB[L,P] == -1 then {label := label + 1;0 0 -1 -1 0 -1 -1 -1 0 0 0search (LB, label, L, P);}}search (LB, label, L, P) {LB[L,P] := label;Nset := neighbors (L, P);For each [L’, P’] in Nset {000-100000-1-10000-100000-10000000-1000If LB[L’, P’] == -1 then search (LB, label, L’, P’);}}


5.3 Counting objects -- method 2Recursive_connected_components (B, LB) {LB := negate (B);Label := 0;Find_components (LB, label);Print (LB);}1 0 0 0 0 0 0 0 0 0 01 -1 0 0 0 -1 -1 -1 0 0 0Find_components (LB, label) {0 0 0 0 0 -1 0 -1 0 -1 -1for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 10 0 0 0 0 -1 0 -1 0 0 0if LB[L,P] == -1 then {label := label + 1;0 0 -1 -1 0 -1 -1 -1 0 0 0search (LB, label, L, P);}}search (LB, label, L, P) {LB[L,P] := label;Nset := neighbors (L, P);For each [L’, P’] in Nset {000-100000-1-10000-100000-10000000-1000If LB[L’, P’] == -1 then search (LB, label, L’, P’);}}


5.3 Counting objects -- method 2Recursive_connected_components (B, LB) {LB := negate (B);Label := 0;Find_components (LB, label);Print (LB);}1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 -1 -1 -1 0 0 0Find_components (LB, label) {0 0 0 0 0 -1 0 -1 0 -1 -1for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 10 0 0 0 0 -1 0 -1 0 0 0if LB[L,P] == -1 then {label := label + 1;0 0 -1 -1 0 -1 -1 -1 0 0 0search (LB, label, L, P);}}search (LB, label, L, P) {LB[L,P] := label;Nset := neighbors (L, P);For each [L’, P’] in Nset {000-100000-1-10000-100000-10000000-1000If LB[L’, P’] == -1 then search (LB, label, L’, P’);}}


5.3 Counting objects -- method 2Recursive_connected_components (B, LB) {LB := negate (B);Label := 0;Find_components (LB, label);Print (LB);}1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 2 -1 -1 0 0 0Find_components (LB, label) {0 0 0 0 0 -1 0 -1 0 -1 -1for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 10 0 0 0 0 -1 0 -1 0 0 0if LB[L,P] == -1 then {label := label + 1;0 0 -1 -1 0 -1 -1 -1 0 0 0search (LB, label, L, P);}}search (LB, label, L, P) {LB[L,P] := label;Nset := neighbors (L, P);For each [L’, P’] in Nset {000-100000-1-10000-100000-10000000-1000If LB[L’, P’] == -1 then search (LB, label, L’, P’);}}


5.3 Counting objects -- method 2Recursive_connected_components (B, LB) {LB := negate (B);Label := 0;Find_components (LB, label);Print (LB);}1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 2 2 -1 0 0 0Find_components (LB, label) {0 0 0 0 0 -1 0 -1 0 -1 -1for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 10 0 0 0 0 -1 0 -1 0 0 0if LB[L,P] == -1 then {label := label + 1;0 0 -1 -1 0 -1 -1 -1 0 0 0search (LB, label, L, P);}}search (LB, label, L, P) {LB[L,P] := label;Nset := neighbors (L, P);For each [L’, P’] in Nset {000-100000-1-10000-100000-10000000-1000If LB[L’, P’] == -1 then search (LB, label, L’, P’);}}


5.3 Counting objects -- method 2Recursive_connected_components (B, LB) {LB := negate (B);Label := 0;Find_components (LB, label);Print (LB);}Find_components (LB, label) {for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {label := label + 1;search (LB, label, L, P);}}search (LB, label, L, P) {LB[L,P] := label;Nset := neighbors (L, P); Problem: ??For each [L’, P’] in Nset {If LB[L’, P’] == -1 then search search (LB, label, L’, P’);}}1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 2 2 2 0 0 00 0 0 0 0 2 0 2 0 3 30 0 0 0 0 2 0 2 0 0 00 0 4 4 0 2 2 2 0 0 00 4 0 4 0 2 0 2 0 0 00 0 0 4 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 5 0


5.3 Counting objects -- method 3Classical Connected Components AlgorithmMakes two passes over the imageClassical_connected_components (B, LB) {LB := negate (B);Label := 0;for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {if L_LAset 0 then{LB[L,P] = Label of LAset}else {label := label + 1;LB[L,P] := label;}}}Print (LB);1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 1 1 1 0 0 00 0 0 0 0 1 0 1 0 1 10 0 0 0 0 0 0 1 0 0 00 0 1 1 0 1 1 1 0 0 00 1 0 1 0 1 0 1 0 0 00 0 0 1 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 1 0


5.3 Counting objects -- method 3Classical Connected Components AlgorithmMakes two passes over the imageClassical_connected_components (B, LB) {LB := negate (B);Label := 0;for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {if L_LAset 0 then{LB[L,P] = Label of LAset}else {label := label + 1;LB[L,P] := label;}}}Print (LB);-1 0 0 0 0 0 0 0 0 0 0-1 -1 0 0 0 -1 -1 -1 0 0 00 0 0 0 0 -1 0 -1 0 -1 -10 0 0 0 0 0 0 -1 0 0 00 0 -1 -1 0 -1 -1 -1 0 0 00 -1 0 -1 0 -1 0 -1 0 0 00 0 0 -1 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 -1 0


5.3 Counting objects -- method 3Classical Connected Components AlgorithmMakes two passes over the imageClassical_connected_components (B, LB) {LB := negate (B);Label := 0;for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {if L_LAset 0 then{LB[L,P] = Label of LAset}else {label := label + 1;LB[L,P] := label;}}}Print (LB);1 0 0 0 0 0 0 0 0 0 0-1 -1 0 0 0 -1 -1 -1 0 0 00 0 0 0 0 -1 0 -1 0 -1 -10 0 0 0 0 0 0 -1 0 0 00 0 -1 -1 0 -1 -1 -1 0 0 00 -1 0 -1 0 -1 0 -1 0 0 00 0 0 -1 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 -1 0


5.3 Counting objects -- method 3Classical Connected Components AlgorithmMakes two passes over the imageClassical_connected_components (B, LB) {LB := negate (B);Label := 0;for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {if L_LAset 0 then{LB[L,P] = Label of LAset}else {label := label + 1;LB[L,P] := label;}}}Print (LB);1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 -1 -1 -1 0 0 00 0 0 0 0 -1 0 -1 0 -1 -10 0 0 0 0 0 0 -1 0 0 00 0 -1 -1 0 -1 -1 -1 0 0 00 -1 0 -1 0 -1 0 -1 0 0 00 0 0 -1 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 -1 0


5.3 Counting objects -- method 3Classical Connected Components AlgorithmMakes two passes over the imageClassical_connected_components (B, LB) {LB := negate (B);Label := 0;for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {if L_LAset 0 then{LB[L,P] = Label of LAset}else {label := label + 1;LB[L,P] := label;}}}Print (LB);1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 2 -1 -1 0 0 00 0 0 0 0 -1 0 -1 0 -1 -10 0 0 0 0 0 0 -1 0 0 00 0 -1 -1 0 -1 -1 -1 0 0 00 -1 0 -1 0 -1 0 -1 0 0 00 0 0 -1 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 -1 0


5.3 Counting objects -- method 3Classical Connected Components AlgorithmMakes two passes over the imageClassical_connected_components (B, LB) {LB := negate (B);Label := 0;for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {if L_LAset 0 then{LB[L,P] = Label of LAset}else {label := label + 1;LB[L,P] := label;}}}Print (LB);1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 2 2 2 0 0 00 0 0 0 0 -1 0 -1 0 -1 -10 0 0 0 0 0 0 -1 0 0 00 0 -1 -1 0 -1 -1 -1 0 0 00 -1 0 -1 0 -1 0 -1 0 0 00 0 0 -1 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 -1 0


5.3 Counting objects -- method 3Classical Connected Components AlgorithmMakes two passes over the imageClassical_connected_components (B, LB) {LB := negate (B);Label := 0;for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {if L_LAset 0 then{LB[L,P] = Label of LAset}else {label := label + 1;LB[L,P] := label;}}}Print (LB);1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 2 2 2 0 0 00 0 0 0 0 2 0 2 0 3 30 0 0 0 0 0 0 -1 0 0 00 0 -1 -1 0 -1 -1 -1 0 0 00 -1 0 -1 0 -1 0 -1 0 0 00 0 0 -1 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 -1 0


5.3 Counting objects -- method 3Classical Connected Components AlgorithmMakes two passes over the imageClassical_connected_components (B, LB) {LB := negate (B);Label := 0;for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {if L_LAset 0 then{LB[L,P] = Label of LAset}else {label := label + 1;LB[L,P] := label;}}}Print (LB);1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 2 2 2 0 0 00 0 0 0 0 2 0 2 0 3 30 0 0 0 0 0 0 2 0 0 00 0 -1 -1 0 -1 -1 -1 0 0 00 -1 0 -1 0 -1 0 -1 0 0 00 0 0 -1 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 -1 0


5.3 Counting objects -- method 3Classical Connected Components AlgorithmMakes two passes over the imageClassical_connected_components (B, LB) {LB := negate (B);Label := 0;for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {if L_LAset 0 then{LB[L,P] = Label of LAset}else {label := label + 1;LB[L,P] := label;}}}Print (LB);1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 2 2 2 0 0 00 0 0 0 0 2 0 2 0 3 30 0 0 0 0 0 0 2 0 0 00 0 4 4 0 5 2 -1 0 0 00 -1 0 -1 0 -1 0 -1 0 0 00 0 0 -1 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 -1 0


5.3 Counting objects -- method 3Classical Connected Components AlgorithmMakes two passes over the imageClassical_connected_components (B, LB) {LB := negate (B);Label := 0;for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {if L_LAset 0 then{LB[L,P] = Label of LAset}else {label := label + 1;LB[L,P] := label;}}}Print (LB);1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 2 2 2 0 0 00 0 0 0 0 2 0 2 0 3 30 0 0 0 0 0 0 2 0 0 00 0 4 4 0 5 2 2 0 0 00 -1 0 -1 0 -1 0 -1 0 0 00 0 0 -1 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 -1 0


5.3 Counting objects -- method 3Classical Connected Components AlgorithmMakes two passes over the imageClassical_connected_components (B, LB) {LB := negate (B);Label := 0;for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {if L_LAset 0 then{LB[L,P] = Label of LAset}else {label := label + 1;LB[L,P] := label;}}}Print (LB);1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 2 2 2 0 0 00 0 0 0 0 2 0 2 0 3 30 0 0 0 0 0 0 2 0 0 00 0 4 4 0 5 2 2 0 0 00 4 0 4 0 5 0 2 0 0 00 0 0 -1 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 -1 0


5.3 Counting objects -- method 3Classical Connected Components AlgorithmMakes two passes over the imageClassical_connected_components (B, LB) {LB := negate (B);Label := 0;for L:= 0 to MaxRow - 1for P:= 0 to MaxCol - 1if LB[L,P] == -1 then {if L_LAset 0 then{LB[L,P] = Label of LAset}else {label := label + 1;LB[L,P] := label;}}}Print (LB);1 0 0 0 0 0 0 0 0 0 01 1 0 0 0 2 2 2 0 0 00 0 0 0 0 2 0 2 0 3 30 0 0 0 0 0 0 2 0 0 00 0 4 4 0 5 2 2 0 0 00 4 0 4 0 5 0 2 0 0 00 0 0 4 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 6 0Problem: overlapping of objectsdue to segmentation error


5.4 <strong>Binary</strong> MorphologyFunction: Extract and alter the structure of objectsin a binary image.Why?<strong>Binary</strong> image is obtained from thresholding. Itcontains unwanted information, such as noisyparticles, objects touching each other, and etc.Morphological operations can address or alleviatethese problems.


5.4 <strong>Binary</strong> MorphologyIllustration?<strong>Binary</strong> image is obtained from thresholding. Itcontains unwanted information, such as noisyparticles, objects touching each other, and etc.Morphological operations can address or alleviatethese problems.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!