1
|
#!/usr/bin/python
|
2
|
|
3
|
from morphee import *
|
4
|
|
5
|
# ------------------------------
|
6
|
# areImagesEqual
|
7
|
# Return 1 if images are equal else 0
|
8
|
# ------------------------------
|
9
|
def areImagesEqual(imIn1, imIn2):
|
10
|
imtemp = ImCreateSame(imIn1)
|
11
|
ImCompare(imIn1, "==", imIn2, 0, 1, imtemp)
|
12
|
return (measVolume(imtemp) == 0)
|
13
|
|
14
|
|
15
|
|
16
|
# ------------------------------
|
17
|
# Lambda-Leveling
|
18
|
# ------------------------------
|
19
|
def lambdaLeveling(imIn, imMark, nl, lamb, imOut):
|
20
|
imTemp = getSame(imMark)
|
21
|
imT = getSame(imMark)
|
22
|
imDilated = getSame(imTemp)
|
23
|
imErode = getSame(imTemp)
|
24
|
imInf = getSame(imTemp)
|
25
|
imSup = getSame(imTemp)
|
26
|
ImCopy(imMark, imTemp)
|
27
|
compteur = 0
|
28
|
|
29
|
while 1:
|
30
|
compteur+=1
|
31
|
ImDilate(imTemp, nl, imDilated)
|
32
|
arithSubImageConstWithClipping(imDilated, lamb, 0, imT)
|
33
|
arithSupImage(imTemp, imT, imDilated)
|
34
|
|
35
|
ImErode(imTemp, nl, imErode)
|
36
|
arithAddImageConstWithClipping(imErode, lamb, 255, imT)
|
37
|
arithInfImage(imTemp, imT, imErode)
|
38
|
|
39
|
arithInfImage(imIn, imDilated, imInf)
|
40
|
arithSupImage(imInf, imErode, imSup)
|
41
|
if (areImagesEqual(imSup, imTemp)):
|
42
|
print "images identiques"
|
43
|
break
|
44
|
else:
|
45
|
ImCopy(imSup, imTemp)
|
46
|
print "lambdaLeveling converge in ", compteur
|
47
|
ImCopy(imSup, imOut)
|
48
|
|
49
|
|
50
|
|
51
|
imIn = fileRead(images_dir+'/Gray/salt.png')
|
52
|
imMark = getSame(imIn)
|
53
|
imOut = getSame(imIn)
|
54
|
imOut2 = getSame(imIn)
|
55
|
|
56
|
#Exemple de ImMark
|
57
|
ImOpen(imIn, HomotheticSE(SquareSE, 3), imMark)
|
58
|
|
59
|
#lambdaLeveling avec la fonction definie plus haut
|
60
|
lambdaLeveling(imIn, imMark, SquareSE, 4, imOut)
|
61
|
fileWrite(imOut, "LevelingTP.png")
|
62
|
|
63
|
#lambdaLeveling usuel de Morph-M
|
64
|
ImLambdaLeveling(imIn, imMark, SquareSE, 4, imOut2)
|
65
|
fileWrite(imOut2, "LevelingMorphee.png")
|
66
|
|
67
|
#Comparaison des 2 Images
|
68
|
imComp = getSame(imIn)
|
69
|
ImCompare(imOut, '==', imOut2, 0, 255, imComp)
|
70
|
fileWrite(imComp, "comparaison.png")
|
71
|
|
72
|
|