1from smilPython import *
2
3def tgdskiz(im1, im2, imMask):
4 tmp1 = Image(im1)
5 tmp2 = Image(im1)
6 sumIm = Image(im1)
7 vol0 = -1
8 vol1 = 0
9 while vol0<vol1:
10 dilate(im1, tmp1, se)
11 dilate(im2, tmp2, se)
12 addNoSat(tmp1, tmp2, sumIm)
13
14
15
16
17def skizBin(label1, label2, maskIm, se=hSE()):
18 tmp1 = Image(label1)
19 tmp2 = Image(label1)
20 lpe = Image(label1)
21 oldVol = 0
22 newVol = -1
23 while oldVol != newVol:
24 dilate(label1, tmp1, se)
25 dilate(label2, tmp2, se)
26 addNoSat(label1, label2, lpe)
27 threshold(lpe, 0, 254, lpe)
28 inf(maskIm, lpe, lpe)
29 mask(tmp1, lpe, tmp1)
30 mask(tmp2, lpe, tmp2)
31 sup(label1, tmp1, label1)
32 sup(label2, tmp2, label2)
33
34 oldVol = newVol
35 newVol = vol(label1)
36 print(newVol)
37
38
39def trueWatershed(imIn, imMark, imOut, se=hSE()):
40
41 label1 = Image(imIn)
42 label2 = Image(imIn)
43 maskIm = Image(imIn)
44 label1.showLabel()
45 label2.showLabel()
46 maskIm.show()
47
48 label(imMark, label1)
49 mask(~label1, label1, label2)
50
51 for i in range(rangeVal(imIn)[1]+1):
52 threshold(imIn, 0, i, maskIm)
53 sup(maskIm, imMark, maskIm)
54 skizBin(label1, label2, maskIm, se)
55
56 copy(label1, imOut)
57
58
59def skizIsotrop(imIn, imOut, se=hSE()):
60 label1 = Image(imIn)
61 label2 = Image(imIn)
62 maskIm = Image(imIn)
63 fill(maskIm, 255)
64
65 label(imIn, label1)
66 mask(~label1, label1, label2)
67
68 label1.showLabel()
69 label2.showLabel()
70 lpe.show()
71 tmp1.showLabel()
72 tmp2.showLabel()
73
74 skizBin(label1, label2, maskIm, se)
75
76