1 from smilPython
import *
4 class customMosaicToGraphFunct(mosaicToGraphFunct_UINT16_UINT16):
5 def initialize(self, imMos, dummy, se):
6 mosaicToGraphFunct_UINT16_UINT16.initialize(self, imMos, dummy, se)
7 self.edges = self.graph.getEdges()
10 def processPixel(self, i, relOffList):
12 curVal = self.imMosaic[i]
14 nbVal = self.imMosaic[i + nb]
17 eInd = self.graph.findEdge(curVal, nbVal)
19 if type(self.imNodeValues)!=type(
None):
20 self.graph.addNode(curVal, self.imNodeValues[i])
21 self.graph.addNode(nbVal, self.imNodeValues[i+nb])
22 if type(self.imEdgeValues)!=type(
None):
23 self.borderValues.append([self.imEdgeValues[i]])
24 self.graph.addEdge(curVal, nbVal, 0,
False)
26 if type(self.imEdgeValues)!=type(
None):
27 self.borderValues[eInd].append(self.imEdgeValues[i])
28 def finalize(self, imMos, dummy, se):
29 mosaicToGraphFunct_UINT16_UINT16.finalize(self, imMos, dummy, se)
30 for i
in range(len(self.borderValues)):
31 values = self.borderValues[i]
32 self.edges[i].weight = sum(values) / len(values)
36 im1 = Image(
"https://smil.cmm.minesparis.psl.eu/images/mosaic.png")
39 imMos = Image(im1,
"UINT16")
46 func = customMosaicToGraphFunct()
47 g = func(imMos, imArea)
49 drawGraph(imMos, g, imSeg)
53 graphToMosaic(imMos, g, imSeg)
RES_T drawOverlay(const Image< T > &imToDraw, Image< T > &imOut)
Draw overlay.
Definition: DImage.hpp:516
size_t label(const Image< T1 > &imIn, Image< T2 > &imOut, const StrElt &se=DEFAULT_SE)
label() - Image labelization
Definition: DMorphoLabel.hpp:564
size_t labelWithArea(const Image< T1 > &imIn, Image< T2 > &imOut, const StrElt &se=DEFAULT_SE)
labelWithArea() - Image labelization with the size (area) of each connected components
Definition: DMorphoLabel.hpp:919