1from smilPython import *
2
3class myAreaExtinction(ExtinctionFlooding_UINT8_UINT16):
4 def createBasins(self, nbr):
5 self.areas = [0]*nbr
6
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
24imIn = Image("https://smil.cmm.minesparis.psl.eu/images/lena.png")
25imGrad = Image(imIn)
26imMark = Image(imIn, "UINT16")
27imExtRank = Image(imIn, "UINT16")
28
29gradient(imIn, imGrad)
30hMinimaLabeled(imGrad, 25, imMark)
31
32aExt = myAreaExtinction()
33aExt.floodWithExtRank(imIn, imMark, imExtRank)
34
35imExtRank.showLabel()
36