Calculation of the minimum spanning tree, simultaneously to the image flooding, with edges weighted according to volume extinction values.
from smilPython import *
imIn = Image("https://smil.cmm.minesparis.psl.eu/images/lena.png")
imGrad = Image(imIn)
imMark = Image(imIn, "UINT16")
imBasins = Image(imMark)
gradient(imIn, imGrad)
hMinimaLabeled(imGrad, 5, imMark)
nRegions = 25
extType = "v"
imGraphOut = Image(imMark)
g = watershedExtinctionGraph(imGrad, imMark, imBasins, extType)
g.removeLowEdges(nRegions)
graphToMosaic(imBasins, g, imGraphOut)
label(imGraphOut, imGraphOut)
imGraphOut.showLabel()
imImgOut = Image(imMark)
watershedExtinction(imGrad, imMark, imImgOut, imBasins, extType)
compare(imImgOut, ">", nRegions, 0, imMark, imMark);
basins(imGrad, imMark, imImgOut)
label(imImgOut, imImgOut)
imImgOut.showLabel()