Project

General

Profile

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

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

1 1 Serge Koudoro
h1. Morph-M Python - Launch some examples
2
3
4
h3. Micro aneurysm detection
5
6
| !retina2.png! |/4.<pre><code class="ruby">
7
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
| !imBuildOpen.png!|
32
|=.*_Result_* |
33
34
h3. Holes detection
35
36
| !gruyere.png! |/4.<pre><code class="ruby">
37
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
| !imFillUnder.png! |
60
|=.*_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
    ##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
    ##Choix Connexité du graphe
71
    nl=NeighborList.neighborsHex2D
72
        
73
    ##Affichage de l'image des grains
74
    fileWrite(im,Image+".png")
75
        
76
    ##Calcule de la fonction distance
77
    print "Compute Distance function:"
78
    print
79
    Distance(im,nl,imDistance)
80
    ImStretchHistogram(imDistance,0,255,imStrech)
81
    fileWrite(imDistance,Image+"_DistanceFunction.png")
82
    fileWrite(imStrech,Image+"_DistanceFunction_0_255.png")
83
84
##Filtage par HMaxima de la fonction distance
85
    ##Parameters HMaxima
86
    TreshHeightMaxima=2
87
    print "Erase lowest maxima, dynamic <=",TreshHeightMaxima
88
    print
89
    ImHMaxima(imDistance,nl,TreshHeightMaxima,imDistanceFilter)
90
    
91
    ##Calule du watershed de la fonction distance
92
    print "Compute watershed in inverse Filter Distance function:"
93
    print
94
    arithInvertImage(imDistanceFilter,imDisInvert)
95
    ImWatershed(imDisInvert,nl,imWs)
96
    ImCompare_ssi(imWs,compareOp.Equal,255,127,im,imWsShowLinesOnInitImage)
97
    fileWrite(imWsShowLinesOnInitImage,Image+"_WsOfDistanceFunctionFilter.png")
98
99
</code></pre> |
100
|=.*_Original Image_* |
101
| !coffee_WsOfDistanceFunctionFilter.png! |
102
|=.*_Result_* |
103
104
105
h3. Road Detection
106
107
| !road.png! | !road_ws.png! |/8.<pre><code class="ruby">
108
109
im = fileRead(images_dir+"/Gray/road.png")
110
imgra = getSame(im)
111
imtmp = getSame(im)
112
imws0 = getSame(im)
113
imws1 = getSame(im)
114
nl=HexSE
115
116
# Segmentation with the waterfall algo.
117
ImMorphoGradient(im,nl,imgra)
118
ImWatershed(imgra,nl,imws0)
119
fileWrite(imws0,"road_ws.png")
120
121
for i in range(3):
122
	ImWaterfalls(imgra,imws0,nl,imws1,imtmp)
123
	fileWrite(imws1,"road_wf"+str(i)+".png")
124
125
	ImCopy(imws1,imws0)
126
</code></pre> |
127
|=.*_Original Image_* |=.*_road_watershed_* |
128
| !road_wf0.png! | !road_wf1.png! |
129
|=.*_road_waterFall 0_* |=.*_road_waterFall 1_* |