Agrandissement taille interface
This commit is contained in:
parent
6cc3468a3d
commit
56ef1ce081
|
@ -251,7 +251,70 @@ class Noise:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# lissage de l'image
|
||||||
|
def smooth(self, pixelMap, seuil=5):
|
||||||
|
width = len( pixelMap[0] )
|
||||||
|
height = len( pixelMap )
|
||||||
|
|
||||||
|
if seuil < 0 or seuil > 255: # si le seuil est incohérent => valeur par défaut (5)
|
||||||
|
seuil = 5;
|
||||||
|
|
||||||
|
|
||||||
|
# on parcourt tout les pixels
|
||||||
|
for y in range(0, len(pixelMap)):
|
||||||
|
for x in range(0, len(pixelMap[y])):
|
||||||
|
|
||||||
|
# on calcule la moyenne des valeurs R G B du pixel courant
|
||||||
|
pMoy = ( pixelMap[y][x].r + pixelMap[y][x].g + pixelMap[y][x].b ) / 3
|
||||||
|
|
||||||
|
|
||||||
|
xmin, ymin, xmax, ymap = x, y, x, y; # les bornes ducarré 3x3 autour du pixel
|
||||||
|
rMoy, gMoy, bMoy, count = 0.0, 0.0, 0.0, 0 # initialisation des variables de moyennes et de total
|
||||||
|
rInterval, gInterval, bInterval, rgbInterval = 0, 0, 0, 0 # initialisation des variables d'intervalles entre les couleurs
|
||||||
|
|
||||||
|
|
||||||
|
# GESTION DES ANGLES
|
||||||
|
|
||||||
|
# ordonnées: borne inférieure
|
||||||
|
if y-1 > -1:
|
||||||
|
ymin = y-1
|
||||||
|
# ordonnées: borne supérieure
|
||||||
|
if y+1 < height:
|
||||||
|
ymax = y+1
|
||||||
|
# abscisses: borne inférieure
|
||||||
|
if x-1 > -1:
|
||||||
|
xmin = x-1
|
||||||
|
# abscisses: borne supérieure
|
||||||
|
if x+1 < width:
|
||||||
|
xmax = x+1
|
||||||
|
|
||||||
|
|
||||||
|
pixels = [ pixelMap[y][xmin], pixelMap[y][xmax], pixelMap[ymin][x], pixelMap[ymax][x] ];
|
||||||
|
for p in pixels:
|
||||||
|
if p != pixelMap[y][x]:
|
||||||
|
rMoy += p.r;
|
||||||
|
gMoy += p.g;
|
||||||
|
bMoy += p.b;
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
# si il y a au moins un pixel autour (normalement tjs mais évite l'erreur div par zéro)
|
||||||
|
if count > 0:
|
||||||
|
# on calcule les moyennes somme(xi) / n
|
||||||
|
rMoy = int( rMoy / count )
|
||||||
|
gMoy = int( gMoy / count )
|
||||||
|
bMoy = int( bMoy / count )
|
||||||
|
|
||||||
|
# calcul de la différence entre les couleurs du pixel et la moyenne des couleurs des pixels autour
|
||||||
|
rInterval = abs( pixelMap[y][x].r - rMoy )
|
||||||
|
gInterval = abs( pixelMap[y][x].g - gMoy )
|
||||||
|
bInterval = abs( pixelMap[y][x].b - bMoy )
|
||||||
|
|
||||||
|
# calcul de la différence en nuance de gris (moyenne des couleurs)
|
||||||
|
rgbInterval = ( rInterval + gInterval + bInterval ) / 3
|
||||||
|
|
||||||
|
# si la couleur est trop "différente" (dépend du seuil) alors on remplace sa couleur par la moyenne des couleurs alentours
|
||||||
|
if rgbInterval > seuil:
|
||||||
|
pixelMap[y][x].setRGB(rMoy, gMoy, bMoy);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
81
code/bmp.py
81
code/bmp.py
|
@ -19,74 +19,83 @@ if len(sys.argv) < 3:
|
||||||
|
|
||||||
################" INTERFACE "###################
|
################" INTERFACE "###################
|
||||||
|
|
||||||
print "+-------------------------+"
|
print "+---------------------------+"
|
||||||
print "| |"
|
print "| |"
|
||||||
print "| TRAITEMENT D'IMAGE |"
|
print "| TRAITEMENT D'IMAGE |"
|
||||||
print "| |"
|
print "| |"
|
||||||
print "+-------------------------+"
|
print "+---------------------------+"
|
||||||
print "| <in> %s |" % exactLength( sys.argv[1], 17, -1)
|
print "| <in> %s |" % exactLength( sys.argv[1], 19, -1)
|
||||||
print "| <out> %s |" % exactLength( sys.argv[2], 17, -1)
|
print "| <out> %s |" % exactLength( sys.argv[2], 19, -1)
|
||||||
print "+-------------------------+"
|
print "+---------------------------+"
|
||||||
print "| %s |" % exactLength("TESTS DE FICHIER", 23, 0)
|
print "| %s |" % exactLength("TESTS DE FICHIER", 25, 0)
|
||||||
print "| %s |" % exactLength("", 23, 0)
|
print "| %s |" % exactLength("", 25, 0)
|
||||||
print "| 0) %s |" % exactLength("Creation manuelle", 20, -1)
|
print "| 0) %s |" % exactLength("Creation manuelle", 21, -1)
|
||||||
print "| 1) %s |" % exactLength("Parse/Unparse", 20, -1)
|
print "| 1) %s |" % exactLength("Parse/Unparse", 21, -1)
|
||||||
print "| 2) %s |" % exactLength("Afficher palette", 20, -1)
|
print "| 2) %s |" % exactLength("Afficher palette", 21, -1)
|
||||||
print "+-------------------------+"
|
print "+---------------------------+"
|
||||||
print "| %s |" % exactLength("TESTS DE BRUIT", 23, 0)
|
print "| %s |" % exactLength("TESTS DE BRUIT", 25, 0)
|
||||||
print "| %s |" % exactLength("", 23, 0)
|
print "| %s |" % exactLength("", 25, 0)
|
||||||
print "| 3) %s |" % exactLength("Salt&Pepper", 20, -1)
|
print "| 10) %s |" % exactLength("Salt&Pepper", 21, -1)
|
||||||
print "| 4) %s |" % exactLength("Additif", 20, -1)
|
print "| 11) %s |" % exactLength("Additif", 21, -1)
|
||||||
print "+-------------------------+"
|
print "| 12) %s |" % exactLength("Lissage", 21, -1)
|
||||||
print "| %s |" % exactLength("TESTS DE DIFFERENCES", 23, 0)
|
print "+---------------------------+"
|
||||||
print "| %s |" % exactLength("", 23, 0)
|
print "| %s |" % exactLength("TESTS DE DIFFERENCES", 25, 0)
|
||||||
print "| 5) %s |" % exactLength("Difference en %", 20, -1)
|
print "| %s |" % exactLength("", 25, 0)
|
||||||
print "| 6) %s |" % exactLength("Difference par P", 20, -1)
|
print "| 20) %s |" % exactLength("Difference en %", 21, -1)
|
||||||
print "| 7) %s |" % exactLength("Difference en image", 20, -1)
|
print "| 21) %s |" % exactLength("Difference par P", 21, -1)
|
||||||
print "| 8) %s |" % exactLength("Fusion d'images (+)", 20, -1)
|
print "| 22) %s |" % exactLength("Difference en image", 21, -1)
|
||||||
print "| 9) %s |" % exactLength("Fusion d'images (-)", 20, -1)
|
print "| 23) %s |" % exactLength("Fusion d'images (+)", 21, -1)
|
||||||
print "+-------------------------+"
|
print "| 24) %s |" % exactLength("Fusion d'images (-)", 21, -1)
|
||||||
|
print "+---------------------------+"
|
||||||
print
|
print
|
||||||
while True:
|
while True:
|
||||||
action = int( raw_input("choix: ") )
|
action = int( raw_input("choix: ") )
|
||||||
if action >= 0 and action <= 9:
|
if action >= 0 and action < 30:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
print
|
print
|
||||||
print "+-------------------------+---------+"
|
print "+---------------------------+---------+"
|
||||||
|
|
||||||
execTime = Timer(); execTime.reset();
|
execTime = Timer(); execTime.reset();
|
||||||
|
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
|
# fichier
|
||||||
if action == 0:
|
if action == 0:
|
||||||
testManualCreation() # teste la création d'un fichier à partir d'une matrice uniquement
|
testManualCreation() # teste la création d'un fichier à partir d'une matrice uniquement
|
||||||
elif action == 1:
|
elif action == 1:
|
||||||
result = testFileIntegrity() # teste le PARSE/UNPARSE
|
result = testFileIntegrity() # teste le PARSE/UNPARSE
|
||||||
elif action == 2:
|
elif action == 2:
|
||||||
result = printIntPalette() # affiche la palette d'une image
|
result = printIntPalette() # affiche la palette d'une image
|
||||||
elif action == 3:
|
|
||||||
|
# bruits
|
||||||
|
elif action == 10:
|
||||||
testSaltAndPepper() # teste le bruitage/débruitage de type "Sel & Poivre"
|
testSaltAndPepper() # teste le bruitage/débruitage de type "Sel & Poivre"
|
||||||
elif action == 4:
|
elif action == 11:
|
||||||
testAdditiveNoise() # teste le bruitage/débruitage de type "Additif"
|
testAdditiveNoise() # teste le bruitage/débruitage de type "Additif"
|
||||||
elif action == 5:
|
elif action == 12:
|
||||||
|
testSmooth() # teste le lissage
|
||||||
|
|
||||||
|
# performances
|
||||||
|
elif action == 20:
|
||||||
printImageQuality() # compare 2 images et donne le pourcentage de ressemblance/différence
|
printImageQuality() # compare 2 images et donne le pourcentage de ressemblance/différence
|
||||||
elif action == 6:
|
elif action == 21:
|
||||||
print "not implemented yet"
|
print "not implemented yet"
|
||||||
exit()
|
exit()
|
||||||
printImageQualityByPower() # compare 2 images et donne le pourcentage de ressemblance/différence (utilisant la puissance)
|
printImageQualityByPower() # compare 2 images et donne le pourcentage de ressemblance/différence (utilisant la puissance)
|
||||||
elif action == 7:
|
elif action == 22:
|
||||||
imageForImageQuality() # crée une image correspondant aux différences de 2 images
|
imageForImageQuality() # crée une image correspondant aux différences de 2 images
|
||||||
elif action == 8:
|
elif action == 23:
|
||||||
mergeImagesAdditive() # crée une image étant la fusion (addition) de 2 images
|
mergeImagesAdditive() # crée une image étant la fusion (addition) de 2 images
|
||||||
elif action == 9:
|
elif action == 24:
|
||||||
mergeImagesSubstractive() # crée une image étant la fusion (soustractive) de 2 images
|
mergeImagesSubstractive() # crée une image étant la fusion (soustractive) de 2 images
|
||||||
else:
|
else:
|
||||||
print "Error! aborting"
|
print "Wrong choice"
|
||||||
|
exit();
|
||||||
|
|
||||||
print "+-------------------------+---------+"
|
print "+---------------------------+---------+"
|
||||||
print "| EXECUTION TIME | %s |" % execTime.get()
|
print "| EXECUTION TIME | %s |" % execTime.get()
|
||||||
print "+-------------------------+---------+"
|
print "+---------------------------+---------+"
|
||||||
print
|
print
|
||||||
print result
|
print result
|
||||||
|
|
||||||
|
|
|
@ -197,8 +197,8 @@ def testSaltAndPepper():
|
||||||
noise.SaltAndPepper_unset(img.content.map, seuil=1, borne=1)
|
noise.SaltAndPepper_unset(img.content.map, seuil=1, borne=1)
|
||||||
print "%s |" % (t.get())
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
print "| Débruitage additif |",; t.reset();
|
print "| Lissage |",; t.reset();
|
||||||
noise.AdditiveNoise_unset(img.content.map);
|
noise.smooth(img.content.map);
|
||||||
print "%s |" % (t.get())
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
# Unparsing
|
# Unparsing
|
||||||
|
@ -296,6 +296,65 @@ def testAdditiveNoise():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# teste les fonction de bruitage et débruitage de type "Additif" #
|
||||||
|
########################################################################
|
||||||
|
# @sysarg 1 le fichier d'origine
|
||||||
|
# @stsarg 2 le fichier de sortie (lissé)
|
||||||
|
#
|
||||||
|
# @history
|
||||||
|
# Parse le fichier d'origine
|
||||||
|
# Lisse le fichier
|
||||||
|
# Unparse l'image et l'enregistre dans le fichier de sortie
|
||||||
|
def testSmooth():
|
||||||
|
|
||||||
|
t = Timer();
|
||||||
|
|
||||||
|
|
||||||
|
# lecture du fichier
|
||||||
|
print "| Reading Image |",; t.reset();
|
||||||
|
with open( sys.argv[1] ) as file:
|
||||||
|
binFile = file.read()
|
||||||
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
|
img = BMPFile(); # Instanciation du BMPFile
|
||||||
|
noise = Noise(); # Instanciation du NoiseObject
|
||||||
|
|
||||||
|
|
||||||
|
# Parsing
|
||||||
|
print "| Parsing file |",; t.reset();
|
||||||
|
img.parse( binFile );
|
||||||
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
|
print "| Smooth image |",; t.reset();
|
||||||
|
noise.smooth(img.content.map, seuil=5)
|
||||||
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
|
# Unparsing
|
||||||
|
print "| Unparsing file |",; t.reset();
|
||||||
|
img.unparse()
|
||||||
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
|
# image to stdout
|
||||||
|
print "| Writing file |",; t.reset();
|
||||||
|
img.write( sys.argv[2] )
|
||||||
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# teste la création d'image manuelle (UNPARSE) à partir d'une matrice uniquement #
|
# teste la création d'image manuelle (UNPARSE) à partir d'une matrice uniquement #
|
||||||
##################################################################################
|
##################################################################################
|
||||||
# @sysarg 1 le fichier de sortie
|
# @sysarg 1 le fichier de sortie
|
||||||
|
@ -419,9 +478,9 @@ def printImageQuality():
|
||||||
percentage = 100.0 * (totalCount-differenceCount) / totalCount
|
percentage = 100.0 * (totalCount-differenceCount) / totalCount
|
||||||
percentage = int(100*percentage)/100.0
|
percentage = int(100*percentage)/100.0
|
||||||
print "%s |" % (t.get())
|
print "%s |" % (t.get())
|
||||||
print "+-------------------------+---------+"
|
print "+---------------------------+---------+"
|
||||||
print "| Commun = %s | |" % exactLength( str(percentage)+"%", 10, -1 );
|
print "| Commun = %s | |" % exactLength( str(percentage)+"%", 12, -1 );
|
||||||
print "| Difference = %s | |" % exactLength( str(100-percentage)+"%", 10, -1 );
|
print "| Difference = %s | |" % exactLength( str(100-percentage)+"%", 12, -1 );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue