200 likes | 643 Views
A MATLAB Tour of Binary Image Analysis. Image Topology: Connectivity. a and b are connected if there exists a path from a to b. How do we define the path for discrete images?. 4-neighbors. 8-neighbors. Depending on the selection of 4-neighbors or 8-neighbors,
E N D
A MATLAB Tour of Binary Image Analysis EE465: Introduction to Digital Image Processing
Image Topology: Connectivity a and b are connected if there exists a path from a to b How do we define the path for discrete images? 4-neighbors 8-neighbors Depending on the selection of 4-neighbors or 8-neighbors, we might have different connectivity result EE465: Introduction to Digital Image Processing
Example q q p p p ~ q no matter 4-neighbors or 8-neighbors p ~ q only when 8-neighbors is considered EE465: Introduction to Digital Image Processing
Component Labeling original binary image If 8-neighbors, two connected components If 4-neighbors, three connected components EE465: Introduction to Digital Image Processing
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. EE465: Introduction to Digital Image Processing
Checkboard Image 4-neighbors Imshow(label2rgb(bwlabel(x,4))) x 8-neighbors Imshow(label2rgb(bwlabel(x,8))) EE465: Introduction to Digital Image Processing
Euler Number EN=-1 EN=0 EN=-3 Euler Number EN=number of connected components – number of holes EE465: Introduction to Digital Image Processing
Chain Codes 4-directional chain code: 0033333323221211101101 8-directional chain code: 076666553321212 EE465: Introduction to Digital Image Processing
MATLAB Implementation EE465: Introduction to Digital Image Processing
Normalization Strategy 33001122 33001122 30011223 00112233 01122330 11223300 12233001 22330011 23300112 00112233 01122330 11223300 12233001 22330011 23300112 33001122 30011223 First row gives the normalized chain code Sort rows 00112233 MATLAB function: sortrows EE465: Introduction to Digital Image Processing
Shape Numbers= Normalized Differential Chain Codes 33010122 33001212 Differential code: dk=ck-ck-1 (mod 4) differentiate differentiate 10113110 10101131 normalize normalize 01011311 01011311 MATLAB function: mod EE465: Introduction to Digital Image Processing
Skeleton Finding via Distance Transform x bwdist(~x,’cityblock’); bwdist(x,’cityblock’); EE465: Introduction to Digital Image Processing
MATLAB Implementation function sk=skeleton_finding(x) % calculate distance transform dt=bwdist(~x,'cityblock'); % find the local maximum n=[0 1;-1 0;0 -1;1 0]; sk=dt>0; for i=1:4 sk=sk&(dt>=circshift(dt,n(i,:))); end EE465: Introduction to Digital Image Processing