SMIL  0.8
 All Classes Functions Variables Groups Pages
constrained_watershed.py

1 from smilPython import *
2 
3 # Load an image
4 imIn = Image("http://cmm.ensmp.fr/~faessel/smil/images/DNA_small.png")
5 imIn.show()
6 
7 # Create a gradient image
8 imGrad = Image(imIn)
9 gradient(imIn, imGrad)
10 
11 # Manually impose markers on image
12 imMark = Image(imIn, "UINT16")
13 imMark << 0
14 # One for the background...
15 imMark.setPixel(75, 40, 1)
16 # and one on two connected particules
17 imMark.setPixel(78, 86, 2)
18 imMark.setPixel(88, 76, 3)
19 
20 # Dilate the markers to avoid to be blocked in a minimum
21 dilate(imMark, imMark, 2)
22 #imMark.showLabel()
23 
24 # Create the watershed
25 imWS = Image(imIn)
26 watershed(imGrad, imMark, imWS)
27 
28 # Display output
29 imWS.show()
30 
31 # Display the output as overlay on the original image
32 imIn.getViewer().drawOverlay(imWS & 1)
33