SMIL  1.0.4
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("https://smil.cmm.minesparis.psl.eu/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 
RES_T hMinimaLabeled(const Image< T1 > &imIn, const T1 &height, Image< T2 > &imOut, const StrElt &se=DEFAULT_SE)
hMinimaLabeled() - Calculate the h-minima and labelize them
Definition: DMorphoExtrema.hpp:182
RES_T gradient(const Image< T > &imIn, Image< T > &imOut, const StrElt &se=DEFAULT_SE)
gradient() - Morphological gradient
Definition: DMorphoResidues.hpp:62