SMIL  0.8
 All Classes Functions Variables Groups Pages
custom_extinction_value.py

1 from smilPython import *
2 
3 class myAreaExtinction(ExtinctionFlooding_UINT8_UINT16):
4  def createBasins(self, nbr):
5  self.areas = [0]*nbr
6  # Call parent class method
7  ExtinctionFlooding_UINT8_UINT16.createBasins(self, nbr)
8  def insertPixel(self, offset, lbl):
9  self.areas[lbl] += 1
10  def mergeBasins(self, lbl1, lbl2):
11  if self.areas[lbl1] > self.areas[lbl2]:
12  eater = lbl1
13  eaten = lbl2
14  else:
15  eater = lbl2
16  eaten = lbl1
17  self.extinctionValues[eaten] = self.areas[eaten]
18  self.areas[eater] += self.areas[eaten]
19  return eater
20  def finalize(self, lbl):
21  self.extinctionValues[lbl] += self.areas[lbl]
22 
23 
24 imIn = Image("http://cmm.ensmp.fr/~faessel/smil/images/lena.png")
25 imGrad = Image(imIn)
26 imMark = Image(imIn, "UINT16")
27 imExtRank = Image(imIn, "UINT16")
28 
29 gradient(imIn, imGrad)
30 hMinimaLabeled(imGrad, 25, imMark)
31 
32 aExt = myAreaExtinction()
33 aExt.floodWithExtRank(imIn, imMark, imExtRank)
34 
35 imExtRank.showLabel()
36