Project

General

Profile

Morph-M Python - Launch some examples » History » Revision 2

Revision 1 (Serge Koudoro, 10/23/2009 03:26 PM) → Revision 2/3 (Serge Koudoro, 10/23/2009 03:35 PM)

h1. Morph-M Python - Launch some examples 


 h3. Micro aneurysm detection 

 | !http://morphm.ensmp.fr/attachments/37/retina2.png! !retina2.png! |/4.<pre><code class="ruby"> 

 #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") 


 </code></pre> | 
 |=.*_Original Image_* | 
 | !http://morphm.ensmp.fr/attachments/39/imBuildOpen.png!| !imBuildOpen.png!| 
 |=.*_Result_* | 

 h3. Holes detection 

 | !http://morphm.ensmp.fr/attachments/38/gruyere.png! !gruyere.png! |/4.<pre><code class="ruby"> 

 ################################################## 
 # 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") 

 </code></pre> | 
 |=.*_Original Image_* | 
 | !http://morphm.ensmp.fr/attachments/40/imFillUnder.png! !imFillUnder.png! | 
 |=.*_Result_* | 

 h3. Coffee segmentation 

 | !coffee.png! |/4.<pre><code class="ruby"> 

 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") 

 </code></pre> | 
 |=.*_Original Image_* | 
 | !http://morphm.ensmp.fr/attachments/41/coffee_WsOfDistanceFunctionFilter.png! !coffee_WsOfDistanceFunctionFilter.png! | 
 |=.*_Result_* | 


 h3. Road Detection 

 | !http://morphm.ensmp.fr/attachments/43/road.png! !road.png! | !http://morphm.ensmp.fr/attachments/44/road_ws.png! !road_ws.png! |/8.<pre><code class="ruby"> 

 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) 
 </code></pre> | 
 |=.*_Original Image_* |=.*_road_watershed_* | 
 | !http://morphm.ensmp.fr/attachments/45/road_wf0.png! !road_wf0.png! | !http://morphm.ensmp.fr/attachments/46/road_wf1.png! !road_wf1.png! | 
 |=.*_road_waterFall 0_* |=.*_road_waterFall 1_* |