from morph import *
S=mmreadgray('pcb1bin.tif')
S[49:70,149:170]=0 # fault simulation
S1=mmclohole(S); # input image
S2=mmopen(S1,mmsedisk(6)); # open for pads
S3=mmcdil(S2,S1,mmsebox(),3); # pads
S4=mmthin(S1); # thinning original
S5=mmthin(S4,mmendpoints(),2); # prunning
S6=mmsupcanon(S5,mmendpoints()); # endpoints
S7=mmsubm(S6,S3); # endpoints not at the pads
S8=mmdil(S7,mmsedisk(6)); # mark endpoints
S9=mmedgeoff(S8); # remove those near the image frame
a=mmgray(S1); #input image
b=mmunion(mmgray(S1,'uint8',130),mmgray(S2));
c=mmunion(mmgray(S1,'uint8',130),mmgray(S3)); #pads
d=mmunion(mmgray(S1,'uint8',130),mmgray(S4)); #thin
e=mmunion(mmgray(S4,'uint8',130),mmgray(S5)); #prunning
f=mmunion(mmgray(S5,'uint8',150),mmdil(mmgray(S6))); #thin, endpoints
g=mmunion(mmgray(S3,'uint8',100),mmdil(mmgray(S6,'uint8',180)),mmdil(mmgray(S7)));
h=mmunion(mmgray(S1,'uint8',130),mmgray(S8));
i=mmunion(mmgray(S1,'uint8',130),mmgray(S9));
mmshow(a)
mmshow(b)
mmshow(c)
mmshow(d)
mmshow(e)
mmshow(f)
mmshow(g)
mmshow(h)
mmshow(i)