Morph-M Python - Launch some examples

Micro aneurysm detection


#Structuring Element
nl = SquareSE

imIn = fileRead(images_dir+"/Gray/retina2.png")
imOut = getSame(imIn)
imTmp = getSame(imIn)

# ..............................
# open and then build
# ..............................
ImOpen(imIn,HomotheticSE(nl,4),imTmp)
ImUnderBuild(imTmp,imIn,nl,imOut)
fileWrite(imOut,"imBuildOpen.png")

# ..............................
# all in one step
# ..............................
#ImEroBuildOpen(imIn, HomotheticSE(nl, 4), nl, imOut)
#fileWrite(imOut,"imEroBuildOpen.png")

Original Image
Result

Holes detection


##################################################
# Fill Holes
##################################################
nl = SquareSE
imIn = fileRead(images_dir+"/Bin/gruyere.png")
imMark = getSame(imIn)
imOut = getSame(imIn)
imTmp = getSame(imIn)
# ..............................
#  with underbuild
# ..............................
arithInvertImage(imIn,imIn)
ImSetConstant(imMark,0)
DrawBorder(imMark,255)
ImUnderBuild(imMark,imIn,nl,imOut)
arithInvertImage(imIn,imIn)
arithInvertImage(imOut,imOut)
fileWrite(imOut,"imFillUnder.png")

Original Image
Result

Coffee segmentation


im=fileRead(images_dir+"/Bin/"+Image+ext)

##Initialisation des images intermédiaires    
imStrech,imDistance,imDistanceFilter,imDisInvert,imWs,imWsShowLinesOnInitImage=getSame(im),getSame(im),getSame(im),getSame(im),getSame(im),getSame(im)

##Choix Connexité du graphe
nl=NeighborList.neighborsHex2D

##Affichage de l'image des grains
fileWrite(im,Image+".png")

##Calcule de la fonction distance
print "Compute Distance function:" 
print
Distance(im,nl,imDistance)
ImStretchHistogram(imDistance,0,255,imStrech)
fileWrite(imDistance,Image+"_DistanceFunction.png")
fileWrite(imStrech,Image+"_DistanceFunction_0_255.png")

##Filtage par HMaxima de la fonction distance
##Parameters HMaxima
TreshHeightMaxima=2
print "Erase lowest maxima, dynamic <=",TreshHeightMaxima
print
ImHMaxima(imDistance,nl,TreshHeightMaxima,imDistanceFilter)

##Calule du watershed de la fonction distance
print "Compute watershed in inverse Filter Distance function:" 
print
arithInvertImage(imDistanceFilter,imDisInvert)
ImWatershed(imDisInvert,nl,imWs)
ImCompare_ssi(imWs,compareOp.Equal,255,127,im,imWsShowLinesOnInitImage)
fileWrite(imWsShowLinesOnInitImage,Image+"_WsOfDistanceFunctionFilter.png")

Original Image
Result

Road Detection


im = fileRead(images_dir+"/Gray/road.png")
imgra = getSame(im)
imtmp = getSame(im)
imws0 = getSame(im)
imws1 = getSame(im)
nl=HexSE

# Segmentation with the waterfall algo.
ImMorphoGradient(im,nl,imgra)
ImWatershed(imgra,nl,imws0)
fileWrite(imws0,"road_ws.png")

for i in range(3):
    ImWaterfalls(imgra,imws0,nl,imws1,imtmp)
    fileWrite(imws1,"road_wf"+str(i)+".png")

    ImCopy(imws1,imws0)
Original Image road_watershed
road_waterFall 0 road_waterFall 1