SMIL  0.9.1
watershed_live.py


1 from smilPython import *
2 
3 class myWSFlooding(WatershedFlooding_UINT8_UINT16):
4  def initialize(self, imIn, imLbl, imOut, se):
5  # Call parent class method
6  WatershedFlooding_UINT8_UINT16.initialize(self, imIn, imLbl, imOut, se)
7  self.imgWS.updatesEnabled = True
8  self.imgLbl.updatesEnabled = True
9  self.nbrPixProcessed = 0
10  self.refresh_every = 10 # refresh every n pixels processed
11  return RES_OK
12  def processPixel(self, offset):
13  # Call parent class method
14  WatershedFlooding_UINT8_UINT16.processPixel(self, offset)
15  if self.nbrPixProcessed>=self.refresh_every:
16  self.imgWS.modified()
17  self.imgLbl.modified()
18  Gui.processEvents()
19  self.nbrPixProcessed = 0
20  else:
21  self.nbrPixProcessed += 1
22 
23 
24 if not "imIn" in globals():
25  imIn = Image("http://smil.cmm.mines-paristech.fr/images/lena.png")
26  imGrad = Image(imIn)
27  imWS = Image(imIn)
28  imMark = Image(imIn, "UINT16")
29  imBasins = Image(imIn, "UINT16")
30 
31 gradient(imIn, imGrad)
32 hMinimaLabeled(imGrad, 10, imMark)
33 
34 imGrad.show()
35 imWS.showLabel()
36 imBasins.showLabel()
37 
38 wsFlood = myWSFlooding()
39 wsFlood.flood(imIn, imMark, imWS, imBasins, sSE())
40 
41 
42 
43