Project

General

Profile

Morph-M Python - Launch some examples » History » Version 3

Serge Koudoro, 10/23/2009 03:37 PM

1 1 Serge Koudoro
h1. Morph-M Python - Launch some examples
2
3
4
h3. Micro aneurysm detection
5
6 2 Serge Koudoro
| !http://morphm.ensmp.fr/attachments/37/retina2.png! |/4.<pre><code class="ruby">
7 1 Serge Koudoro
8
#Structuring Element
9
nl = SquareSE
10
11
imIn = fileRead(images_dir+"/Gray/retina2.png")
12
imOut = getSame(imIn)
13
imTmp = getSame(imIn)
14
15
# ..............................
16
# open and then build
17
# ..............................
18
ImOpen(imIn,HomotheticSE(nl,4),imTmp)
19
ImUnderBuild(imTmp,imIn,nl,imOut)
20
fileWrite(imOut,"imBuildOpen.png")
21
22
# ..............................
23
# all in one step
24
# ..............................
25
#ImEroBuildOpen(imIn, HomotheticSE(nl, 4), nl, imOut)
26
#fileWrite(imOut,"imEroBuildOpen.png")
27
28
29
</code></pre> |
30
|=.*_Original Image_* |
31 2 Serge Koudoro
| !http://morphm.ensmp.fr/attachments/39/imBuildOpen.png!|
32 1 Serge Koudoro
|=.*_Result_* |
33
34
h3. Holes detection
35
36 2 Serge Koudoro
| !http://morphm.ensmp.fr/attachments/38/gruyere.png! |/4.<pre><code class="ruby">
37 1 Serge Koudoro
38
##################################################
39
# Fill Holes
40
##################################################
41
nl = SquareSE
42
imIn = fileRead(images_dir+"/Bin/gruyere.png")
43
imMark = getSame(imIn)
44
imOut = getSame(imIn)
45
imTmp = getSame(imIn)
46
# ..............................
47
#  with underbuild
48
# ..............................
49
arithInvertImage(imIn,imIn)
50
ImSetConstant(imMark,0)
51
DrawBorder(imMark,255)
52
ImUnderBuild(imMark,imIn,nl,imOut)
53
arithInvertImage(imIn,imIn)
54
arithInvertImage(imOut,imOut)
55
fileWrite(imOut,"imFillUnder.png")
56
57
</code></pre> |
58
|=.*_Original Image_* |
59 2 Serge Koudoro
| !http://morphm.ensmp.fr/attachments/40/imFillUnder.png! |
60 1 Serge Koudoro
|=.*_Result_* |
61
62
h3. Coffee segmentation
63
64
| !coffee.png! |/4.<pre><code class="ruby">
65
66
im=fileRead(images_dir+"/Bin/"+Image+ext)
67
68 3 Serge Koudoro
##Initialisation des images intermédiaires    
69
imStrech,imDistance,imDistanceFilter,imDisInvert,imWs,imWsShowLinesOnInitImage=getSame(im),getSame(im),getSame(im),getSame(im),getSame(im),getSame(im)
70
71
##Choix Connexité du graphe
72
nl=NeighborList.neighborsHex2D
73 1 Serge Koudoro
        
74 3 Serge Koudoro
##Affichage de l'image des grains
75
fileWrite(im,Image+".png")
76 1 Serge Koudoro
        
77 3 Serge Koudoro
##Calcule de la fonction distance
78
print "Compute Distance function:"
79
print
80
Distance(im,nl,imDistance)
81
ImStretchHistogram(imDistance,0,255,imStrech)
82
fileWrite(imDistance,Image+"_DistanceFunction.png")
83
fileWrite(imStrech,Image+"_DistanceFunction_0_255.png")
84 1 Serge Koudoro
85
##Filtage par HMaxima de la fonction distance
86 3 Serge Koudoro
##Parameters HMaxima
87
TreshHeightMaxima=2
88
print "Erase lowest maxima, dynamic <=",TreshHeightMaxima
89
print
90
ImHMaxima(imDistance,nl,TreshHeightMaxima,imDistanceFilter)
91 1 Serge Koudoro
    
92 3 Serge Koudoro
##Calule du watershed de la fonction distance
93
print "Compute watershed in inverse Filter Distance function:"
94
print
95
arithInvertImage(imDistanceFilter,imDisInvert)
96
ImWatershed(imDisInvert,nl,imWs)
97
ImCompare_ssi(imWs,compareOp.Equal,255,127,im,imWsShowLinesOnInitImage)
98
fileWrite(imWsShowLinesOnInitImage,Image+"_WsOfDistanceFunctionFilter.png")
99 1 Serge Koudoro
100
</code></pre> |
101
|=.*_Original Image_* |
102 2 Serge Koudoro
| !http://morphm.ensmp.fr/attachments/41/coffee_WsOfDistanceFunctionFilter.png! |
103 1 Serge Koudoro
|=.*_Result_* |
104
105
106
h3. Road Detection
107
108 2 Serge Koudoro
| !http://morphm.ensmp.fr/attachments/43/road.png! | !http://morphm.ensmp.fr/attachments/44/road_ws.png! |/8.<pre><code class="ruby">
109 1 Serge Koudoro
110
im = fileRead(images_dir+"/Gray/road.png")
111
imgra = getSame(im)
112
imtmp = getSame(im)
113
imws0 = getSame(im)
114
imws1 = getSame(im)
115
nl=HexSE
116
117
# Segmentation with the waterfall algo.
118
ImMorphoGradient(im,nl,imgra)
119
ImWatershed(imgra,nl,imws0)
120
fileWrite(imws0,"road_ws.png")
121
122
for i in range(3):
123
	ImWaterfalls(imgra,imws0,nl,imws1,imtmp)
124
	fileWrite(imws1,"road_wf"+str(i)+".png")
125
126
	ImCopy(imws1,imws0)
127
</code></pre> |
128
|=.*_Original Image_* |=.*_road_watershed_* |
129 2 Serge Koudoro
| !http://morphm.ensmp.fr/attachments/45/road_wf0.png! | !http://morphm.ensmp.fr/attachments/46/road_wf1.png! |
130 1 Serge Koudoro
|=.*_road_waterFall 0_* |=.*_road_waterFall 1_* |