Ajout de la possibilté de recharger l'image ou d'enchaîner les actions
Before Width: | Height: | Size: 257 KiB |
Before Width: | Height: | Size: 257 KiB |
|
@ -304,6 +304,8 @@ class BMPContent:
|
||||||
#################################
|
#################################
|
||||||
class RGBPixel:
|
class RGBPixel:
|
||||||
def __init__(self, r=0, g=0, b=0, x=-1, y=-1, bpp=24):
|
def __init__(self, r=0, g=0, b=0, x=-1, y=-1, bpp=24):
|
||||||
|
self.done = False;
|
||||||
|
|
||||||
if bpp not in [1,4,8,24]:
|
if bpp not in [1,4,8,24]:
|
||||||
if not hasattr(self, 'bpp'): # si l'attribut n'est pas déjà défini, alors on met la valeur par défaut
|
if not hasattr(self, 'bpp'): # si l'attribut n'est pas déjà défini, alors on met la valeur par défaut
|
||||||
self.bpp = 24
|
self.bpp = 24
|
||||||
|
@ -328,8 +330,8 @@ class RGBPixel:
|
||||||
self.intData = [ int( (r+g+b) / 3 ) ]
|
self.intData = [ int( (r+g+b) / 3 ) ]
|
||||||
self.binData = chr( self.intData[0] )
|
self.binData = chr( self.intData[0] )
|
||||||
else:
|
else:
|
||||||
self.intData = [ r, g, b ]
|
self.intData = [ b, g, r ]
|
||||||
self.binData = chr(g) + chr(b) + chr(r)
|
self.binData = chr(b) + chr(g) + chr(r)
|
||||||
|
|
||||||
|
|
||||||
def setRGB(self, r=0, g=0, b=0, x=None, y=None, bpp=24):
|
def setRGB(self, r=0, g=0, b=0, x=None, y=None, bpp=24):
|
||||||
|
|
Before Width: | Height: | Size: 257 KiB After Width: | Height: | Size: 227 KiB |
470
code/main.py
|
@ -10,6 +10,7 @@ from tests import *
|
||||||
|
|
||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
|
from os import system as sh
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# test par défaut puis quitte
|
# test par défaut puis quitte
|
||||||
|
@ -25,235 +26,272 @@ if len(sys.argv) < 3:
|
||||||
|
|
||||||
|
|
||||||
################" INTERFACE "###################
|
################" INTERFACE "###################
|
||||||
|
def interfaceLoop():
|
||||||
|
sh('clear');
|
||||||
|
print "+---------------------------+"
|
||||||
|
print "| |"
|
||||||
|
print "| TRAITEMENT D'IMAGE |"
|
||||||
|
print "| |"
|
||||||
|
print "+---------------------------+"
|
||||||
|
print "| <in> %s |" % exactLength( sys.argv[1], 19, -1)
|
||||||
|
print "| <out> %s |" % exactLength( sys.argv[2], 19, -1)
|
||||||
|
print "+---------------------------+"
|
||||||
|
print "| %s |" % exactLength("TESTS DE FICHIER", 25, 0)
|
||||||
|
print "| %s |" % exactLength("", 25, 0)
|
||||||
|
print "| 0) %s |" % exactLength("Creation manuelle", 21, -1)
|
||||||
|
print "| 1) %s |" % exactLength("Parse/Unparse", 21, -1)
|
||||||
|
print "| 2) %s |" % exactLength("Afficher palette", 21, -1)
|
||||||
|
print "+---------------------------+"
|
||||||
|
print "| %s |" % exactLength("TESTS DE BRUIT", 25, 0)
|
||||||
|
print "| %s |" % exactLength("", 25, 0)
|
||||||
|
print "| 10) %s |" % exactLength("Salt&Pepper", 21, -1)
|
||||||
|
print "| 11) %s |" % exactLength("Additif (Bernouilli)", 21, -1)
|
||||||
|
print "| 12) %s |" % exactLength("Additif (Gaussien)", 21, -1)
|
||||||
|
print "+---------------------------+"
|
||||||
|
print "| %s |" % exactLength("TESTS DE DIFFERENCES", 25, 0)
|
||||||
|
print "| %s |" % exactLength("", 25, 0)
|
||||||
|
print "| 20) %s |" % exactLength("Difference en %", 21, -1)
|
||||||
|
print "| 21) %s |" % exactLength("SNR (origine/bruit)", 21, -1)
|
||||||
|
print "| 22) %s |" % exactLength("Difference en image", 21, -1)
|
||||||
|
print "| 23) %s |" % exactLength("Fusion d'images (+)", 21, -1)
|
||||||
|
print "| 24) %s |" % exactLength("Fusion d'images (-)", 21, -1)
|
||||||
|
print "+---------------------------+"
|
||||||
|
print "| %s |" % exactLength("TESTS DE FORMES", 25, 0)
|
||||||
|
print "| %s |" % exactLength("", 25, 0)
|
||||||
|
print "| 30) %s |" % exactLength("Reveler une teinte", 21, -1)
|
||||||
|
print "| 31) %s |" % exactLength("Colorer une forme", 21, -1)
|
||||||
|
print "| 32) %s |" % exactLength("Colorer les formes", 21, -1)
|
||||||
|
print "| 33) %s |" % exactLength("Relever les contours", 21, -1)
|
||||||
|
print "+---------------------------+"
|
||||||
|
print "| %s |" % exactLength("TESTS DE FILTRES", 25, 0)
|
||||||
|
print "| %s |" % exactLength("", 25, 0)
|
||||||
|
print "| 40) %s |" % exactLength("Filtre moyen", 21, -1)
|
||||||
|
print "| 41) %s |" % exactLength("Laplace", 21, -1)
|
||||||
|
print "| 42) %s |" % exactLength("Roberts", 21, -1)
|
||||||
|
print "| 43) %s |" % exactLength("Prewitt", 21, -1)
|
||||||
|
print "| 44) %s |" % exactLength("Sobel", 21, -1)
|
||||||
|
print "| 45) %s |" % exactLength("Convolution", 21, -1)
|
||||||
|
print "| 46) %s |" % exactLength("bichrome", 21, -1)
|
||||||
|
print "| 47) %s |" % exactLength("Passe Haut", 21, -1)
|
||||||
|
print "+---------------------------+"
|
||||||
|
print
|
||||||
|
while True:
|
||||||
|
action = int( raw_input("choix: ") )
|
||||||
|
if action >= 0 and action < 50:
|
||||||
|
break;
|
||||||
|
|
||||||
|
startStr = "\n+---------------------------+---------+"
|
||||||
|
result = ""
|
||||||
|
execTime = Timer(); execTime.reset();
|
||||||
|
|
||||||
|
|
||||||
|
# fichier
|
||||||
|
if action == 0:
|
||||||
|
w = raw_input("width [100]: ")
|
||||||
|
h = raw_input("height [100]: ")
|
||||||
|
arg1, arg2 = 100, 100
|
||||||
|
if w != "":
|
||||||
|
arg1 = int(w)
|
||||||
|
if h != "":
|
||||||
|
arg2 = int(h)
|
||||||
|
print startStr
|
||||||
|
testManualCreation(arg1, arg2) # teste la création d'un fichier à partir d'une matrice uniquement
|
||||||
|
elif action == 1:
|
||||||
|
print startStr
|
||||||
|
result = testFileIntegrity(image1) # teste le PARSE/UNPARSE
|
||||||
|
elif action == 2:
|
||||||
|
print startStr
|
||||||
|
result = printIntPalette(image1) # affiche la palette d'une image
|
||||||
|
|
||||||
|
# bruits
|
||||||
|
elif action == 10:
|
||||||
|
inS = raw_input("seuil bruitage [50]: ")
|
||||||
|
outS = raw_input("seuil débruitage [1] : ")
|
||||||
|
outB = raw_input("borne débruitage [1] : ")
|
||||||
|
s = raw_input("Lissage ? (0-1): ")
|
||||||
|
arg1, arg2, arg3, arg4 = 50, 1, 1, 1
|
||||||
|
if inS != "":
|
||||||
|
arg1 = int(inS)
|
||||||
|
if outS != "":
|
||||||
|
arg2 = int(outS)
|
||||||
|
if outB != "":
|
||||||
|
arg3 = int(outB)
|
||||||
|
if s != "":
|
||||||
|
arg4 = int(s)
|
||||||
|
print startStr
|
||||||
|
testSaltAndPepper(image1, arg1, arg2, arg3, arg4) # teste le bruitage/débruitage de type "Sel & Poivre"
|
||||||
|
elif action == 11:
|
||||||
|
inS = raw_input("seuil bruitage [10]: ")
|
||||||
|
outS = raw_input("seuil débruitage [35] : ")
|
||||||
|
arg1, arg2 = 10, 35
|
||||||
|
if inS != "":
|
||||||
|
arg1 = int(inS)
|
||||||
|
if outS != "":
|
||||||
|
arg2 = int(outS)
|
||||||
|
print startStr
|
||||||
|
testAdditiveBernouilliNoise(image1, arg1, arg2) # teste le bruitage/débruitage de type "Additif"
|
||||||
|
elif action == 12:
|
||||||
|
inS = raw_input("sigma [10]: ")
|
||||||
|
outS = raw_input("seuil débruitage [35] : ")
|
||||||
|
arg1, arg2 = 10, 35
|
||||||
|
if inS != "":
|
||||||
|
arg1 = int(inS)
|
||||||
|
if outS != "":
|
||||||
|
arg2 = int(outS)
|
||||||
|
print startStr
|
||||||
|
testAdditiveGaussianNoise(image1, arg1, arg2) # teste le bruitage/débruitage de type "Additif"
|
||||||
|
# performances
|
||||||
|
elif action == 20:
|
||||||
|
print startStr
|
||||||
|
printImageQuality(image1, image2) # compare 2 images et donne le pourcentage de ressemblance/différence
|
||||||
|
elif action == 21:
|
||||||
|
print startStr
|
||||||
|
printSNR(image1, image2) # compare 2 images et retourne le SNR
|
||||||
|
elif action == 22:
|
||||||
|
print startStr
|
||||||
|
imageForImageQuality(image1, image2) # crée une image correspondant aux différences de 2 images
|
||||||
|
elif action == 23:
|
||||||
|
print startStr
|
||||||
|
mergeImagesAdditive(image1, image2) # crée une image étant la fusion (addition) de 2 images
|
||||||
|
elif action == 24:
|
||||||
|
print startStr
|
||||||
|
mergeImagesSubstractive(image1, image2) # crée une image étant la fusion (soustractive) de 2 images
|
||||||
|
elif action == 30:
|
||||||
|
r = raw_input("rouge [0]: ")
|
||||||
|
g = raw_input("vert [0]: ")
|
||||||
|
b = raw_input("bleu [0]: ")
|
||||||
|
s = raw_input("seuil [50]: ")
|
||||||
|
arg1, arg2, arg3, arg4 = 0,0,0,50
|
||||||
|
if r != "":
|
||||||
|
arg1 = int(r)
|
||||||
|
if g != "":
|
||||||
|
arg2 = int(g)
|
||||||
|
if b != "":
|
||||||
|
arg3 = int(b)
|
||||||
|
if s != "":
|
||||||
|
arg4 = int(s)
|
||||||
|
print startStr
|
||||||
|
revealShapes(image1, arg1, arg2, arg3, arg4) # révèle la couleur spécifiée
|
||||||
|
elif action == 31:
|
||||||
|
x = raw_input("abscisses(x) [0]: ")
|
||||||
|
y = raw_input("ordonnées(y) [0]: ")
|
||||||
|
arg1, arg2 = 0,0
|
||||||
|
if x != "":
|
||||||
|
arg1 = int(x)
|
||||||
|
if y != "":
|
||||||
|
arg2 = int(y)
|
||||||
|
print startStr
|
||||||
|
colorShape(image1, arg1, arg2) # colorie la forme contenant le pixel de coordonnées donné
|
||||||
|
elif action == 32:
|
||||||
|
print startStr
|
||||||
|
colorAllShapes(image1) # colorie la forme contenant le pixel de coordonnées donné
|
||||||
|
elif action == 33:
|
||||||
|
print startStr
|
||||||
|
testStroke(image1) # trace les contours uniquement à partir de formes pleines
|
||||||
|
|
||||||
|
|
||||||
|
# filtres
|
||||||
|
elif action == 40:
|
||||||
|
print startStr
|
||||||
|
testAverageFilter(image1) # teste le lissage
|
||||||
|
elif action == 41:
|
||||||
|
print startStr
|
||||||
|
testLaplace(image1) # teste le filtre de Laplace
|
||||||
|
elif action == 42:
|
||||||
|
print startStr
|
||||||
|
testRoberts(image1) # teste le filtre de Roberts
|
||||||
|
elif action == 43:
|
||||||
|
print startStr
|
||||||
|
testPrewitt(image1) # teste le filtre de Prewitt
|
||||||
|
elif action == 44:
|
||||||
|
print startStr
|
||||||
|
testSobel(image1) # teste le filtre de Sobel
|
||||||
|
elif action == 45:
|
||||||
|
print startStr
|
||||||
|
testConvolution(image1) # teste le filtre de Convolution
|
||||||
|
elif action == 46:
|
||||||
|
print startStr
|
||||||
|
testBichrome(image1) # teste le passage au bichromatique
|
||||||
|
elif action == 47:
|
||||||
|
print startStr
|
||||||
|
testHighPass(image1) # teste le filtre passe haut
|
||||||
|
|
||||||
|
else:
|
||||||
|
print "Wrong choice"
|
||||||
|
exit();
|
||||||
|
|
||||||
|
print "+---------------------------+---------+"
|
||||||
|
print "| EXECUTION TIME | %s |" % execTime.get()
|
||||||
|
print "+---------------------------+---------+"
|
||||||
|
print
|
||||||
|
print result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print '- [PRESS ANY KEY TO CONTINUE] -';
|
||||||
|
print '- [ BUT PRESS "Q" TO QUIT ] -';
|
||||||
|
loopKey = raw_input('- [ OR PRESS "R" TO RELOAD ] -');
|
||||||
|
|
||||||
|
if( loopKey == 'q' or loopKey == 'Q' ):
|
||||||
|
exit();
|
||||||
|
elif( loopKey == 'r' or loopKey == 'R' ):
|
||||||
|
loadFiles();
|
||||||
|
|
||||||
|
interfaceLoop();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
################" EXECUTABLE "###################
|
||||||
|
|
||||||
|
sh('clear');
|
||||||
|
|
||||||
print "+---------------------------+"
|
print "+---------------------------+"
|
||||||
print "| |"
|
print "| |"
|
||||||
print "| TRAITEMENT D'IMAGE |"
|
print "| CHARGEMENT... |"
|
||||||
print "| |"
|
print "| |"
|
||||||
print "+---------------------------+"
|
print "+---------------------------+"
|
||||||
|
|
||||||
# ON CREE LES IMAGES
|
# ON CREE LES IMAGES
|
||||||
image1 = BMPFile();
|
image1, file1 = BMPFile(), "";
|
||||||
image2 = BMPFile();
|
image2, file2 = BMPFile(), "";
|
||||||
|
|
||||||
|
|
||||||
with open( sys.argv[1] ) as file:
|
with open( sys.argv[1] ) as file:
|
||||||
image1.parse( file.read() );
|
file1 += file.read();
|
||||||
|
|
||||||
for line in image1.content.map:
|
|
||||||
for pix in line:
|
|
||||||
image1.drawer.setPixel( pix );
|
|
||||||
image1.drawer.refresh();
|
|
||||||
|
|
||||||
print "| <in> %s |" % exactLength( sys.argv[1], 19, -1)
|
|
||||||
|
|
||||||
|
|
||||||
with open( sys.argv[2] ) as file:
|
with open( sys.argv[2] ) as file:
|
||||||
image2.parse( file.read() )
|
file2 += file.read()
|
||||||
print "| <out> %s |" % exactLength( sys.argv[2], 19, -1)
|
|
||||||
|
|
||||||
|
def loadFiles():
|
||||||
|
image1.parse( file1 );
|
||||||
|
|
||||||
|
for line in image1.content.map:
|
||||||
|
for pix in line:
|
||||||
|
image1.drawer.setPixel( pix );
|
||||||
|
image1.drawer.refresh();
|
||||||
|
|
||||||
################" INTERFACE "###################
|
try:
|
||||||
|
image2.parse( file2 );
|
||||||
|
except Exception as e:
|
||||||
|
print e;
|
||||||
|
loadFiles();
|
||||||
|
|
||||||
# print "+---------------------------+"
|
interfaceLoop();
|
||||||
# print "| |"
|
|
||||||
# print "| TRAITEMENT D'IMAGE |"
|
|
||||||
# print "| |"
|
|
||||||
# print "+---------------------------+"
|
|
||||||
# print "| <in> %s |" % exactLength( sys.argv[1], 19, -1)
|
|
||||||
# print "| <out> %s |" % exactLength( sys.argv[2], 19, -1)
|
|
||||||
print "+---------------------------+"
|
|
||||||
print "| %s |" % exactLength("TESTS DE FICHIER", 25, 0)
|
|
||||||
print "| %s |" % exactLength("", 25, 0)
|
|
||||||
print "| 0) %s |" % exactLength("Creation manuelle", 21, -1)
|
|
||||||
print "| 1) %s |" % exactLength("Parse/Unparse", 21, -1)
|
|
||||||
print "| 2) %s |" % exactLength("Afficher palette", 21, -1)
|
|
||||||
print "+---------------------------+"
|
|
||||||
print "| %s |" % exactLength("TESTS DE BRUIT", 25, 0)
|
|
||||||
print "| %s |" % exactLength("", 25, 0)
|
|
||||||
print "| 10) %s |" % exactLength("Salt&Pepper", 21, -1)
|
|
||||||
print "| 11) %s |" % exactLength("Additif (Bernouilli)", 21, -1)
|
|
||||||
print "| 12) %s |" % exactLength("Additif (Gaussien)", 21, -1)
|
|
||||||
print "+---------------------------+"
|
|
||||||
print "| %s |" % exactLength("TESTS DE DIFFERENCES", 25, 0)
|
|
||||||
print "| %s |" % exactLength("", 25, 0)
|
|
||||||
print "| 20) %s |" % exactLength("Difference en %", 21, -1)
|
|
||||||
print "| 21) %s |" % exactLength("SNR (origine/bruit)", 21, -1)
|
|
||||||
print "| 22) %s |" % exactLength("Difference en image", 21, -1)
|
|
||||||
print "| 23) %s |" % exactLength("Fusion d'images (+)", 21, -1)
|
|
||||||
print "| 24) %s |" % exactLength("Fusion d'images (-)", 21, -1)
|
|
||||||
print "+---------------------------+"
|
|
||||||
print "| %s |" % exactLength("TESTS DE FORMES", 25, 0)
|
|
||||||
print "| %s |" % exactLength("", 25, 0)
|
|
||||||
print "| 30) %s |" % exactLength("Reveler une teinte", 21, -1)
|
|
||||||
print "| 31) %s |" % exactLength("Colorer une forme", 21, -1)
|
|
||||||
print "| 32) %s |" % exactLength("Colorer les formes", 21, -1)
|
|
||||||
print "| 33) %s |" % exactLength("Relever les contours", 21, -1)
|
|
||||||
print "+---------------------------+"
|
|
||||||
print "| %s |" % exactLength("TESTS DE FILTRES", 25, 0)
|
|
||||||
print "| %s |" % exactLength("", 25, 0)
|
|
||||||
print "| 40) %s |" % exactLength("Filtre moyen", 21, -1)
|
|
||||||
print "| 41) %s |" % exactLength("Laplace", 21, -1)
|
|
||||||
print "| 42) %s |" % exactLength("Roberts", 21, -1)
|
|
||||||
print "| 43) %s |" % exactLength("Prewitt", 21, -1)
|
|
||||||
print "| 44) %s |" % exactLength("Sobel", 21, -1)
|
|
||||||
print "| 45) %s |" % exactLength("Convolution", 21, -1)
|
|
||||||
print "| 46) %s |" % exactLength("bichrome", 21, -1)
|
|
||||||
print "| 47) %s |" % exactLength("Passe Haut", 21, -1)
|
|
||||||
print "+---------------------------+"
|
|
||||||
print
|
|
||||||
while True:
|
|
||||||
action = int( raw_input("choix: ") )
|
|
||||||
if action >= 0 and action < 50:
|
|
||||||
break;
|
|
||||||
|
|
||||||
startStr = "\n+---------------------------+---------+"
|
|
||||||
result = ""
|
|
||||||
execTime = Timer(); execTime.reset();
|
|
||||||
|
|
||||||
|
|
||||||
# fichier
|
|
||||||
if action == 0:
|
|
||||||
w = raw_input("width [100]: ")
|
|
||||||
h = raw_input("height [100]: ")
|
|
||||||
arg1, arg2 = 100, 100
|
|
||||||
if w != "":
|
|
||||||
arg1 = int(w)
|
|
||||||
if h != "":
|
|
||||||
arg2 = int(h)
|
|
||||||
print startStr
|
|
||||||
testManualCreation(arg1, arg2) # teste la création d'un fichier à partir d'une matrice uniquement
|
|
||||||
elif action == 1:
|
|
||||||
print startStr
|
|
||||||
result = testFileIntegrity(image1) # teste le PARSE/UNPARSE
|
|
||||||
elif action == 2:
|
|
||||||
print startStr
|
|
||||||
result = printIntPalette(image1) # affiche la palette d'une image
|
|
||||||
|
|
||||||
# bruits
|
|
||||||
elif action == 10:
|
|
||||||
inS = raw_input("seuil bruitage [50]: ")
|
|
||||||
outS = raw_input("seuil débruitage [1] : ")
|
|
||||||
outB = raw_input("borne débruitage [1] : ")
|
|
||||||
s = raw_input("Lissage ? (0-1): ")
|
|
||||||
arg1, arg2, arg3, arg4 = 50, 1, 1, 1
|
|
||||||
if inS != "":
|
|
||||||
arg1 = int(inS)
|
|
||||||
if outS != "":
|
|
||||||
arg2 = int(outS)
|
|
||||||
if outB != "":
|
|
||||||
arg3 = int(outB)
|
|
||||||
if s != "":
|
|
||||||
arg4 = int(s)
|
|
||||||
print startStr
|
|
||||||
testSaltAndPepper(image1, arg1, arg2, arg3, arg4) # teste le bruitage/débruitage de type "Sel & Poivre"
|
|
||||||
elif action == 11:
|
|
||||||
inS = raw_input("seuil bruitage [10]: ")
|
|
||||||
outS = raw_input("seuil débruitage [35] : ")
|
|
||||||
arg1, arg2 = 10, 35
|
|
||||||
if inS != "":
|
|
||||||
arg1 = int(inS)
|
|
||||||
if outS != "":
|
|
||||||
arg2 = int(outS)
|
|
||||||
print startStr
|
|
||||||
testAdditiveBernouilliNoise(image1, arg1, arg2) # teste le bruitage/débruitage de type "Additif"
|
|
||||||
elif action == 12:
|
|
||||||
inS = raw_input("sigma [10]: ")
|
|
||||||
outS = raw_input("seuil débruitage [35] : ")
|
|
||||||
arg1, arg2 = 10, 35
|
|
||||||
if inS != "":
|
|
||||||
arg1 = int(inS)
|
|
||||||
if outS != "":
|
|
||||||
arg2 = int(outS)
|
|
||||||
print startStr
|
|
||||||
testAdditiveGaussianNoise(image1, arg1, arg2) # teste le bruitage/débruitage de type "Additif"
|
|
||||||
# performances
|
|
||||||
elif action == 20:
|
|
||||||
print startStr
|
|
||||||
printImageQuality(image1) # compare 2 images et donne le pourcentage de ressemblance/différence
|
|
||||||
elif action == 21:
|
|
||||||
print startStr
|
|
||||||
printSNR(image1) # compare 2 images et retourne le SNR
|
|
||||||
elif action == 22:
|
|
||||||
print startStr
|
|
||||||
imageForImageQuality(image1) # crée une image correspondant aux différences de 2 images
|
|
||||||
elif action == 23:
|
|
||||||
print startStr
|
|
||||||
mergeImagesAdditive(image1) # crée une image étant la fusion (addition) de 2 images
|
|
||||||
elif action == 24:
|
|
||||||
print startStr
|
|
||||||
mergeImagesSubstractive(image1) # crée une image étant la fusion (soustractive) de 2 images
|
|
||||||
elif action == 30:
|
|
||||||
r = raw_input("rouge [0]: ")
|
|
||||||
g = raw_input("vert [0]: ")
|
|
||||||
b = raw_input("bleu [0]: ")
|
|
||||||
s = raw_input("seuil [50]: ")
|
|
||||||
arg1, arg2, arg3, arg4 = 0,0,0,50
|
|
||||||
if r != "":
|
|
||||||
arg1 = int(r)
|
|
||||||
if g != "":
|
|
||||||
arg2 = int(g)
|
|
||||||
if b != "":
|
|
||||||
arg3 = int(b)
|
|
||||||
if s != "":
|
|
||||||
arg4 = int(s)
|
|
||||||
print startStr
|
|
||||||
revealShapes(image1, arg1, arg2, arg3, arg4) # révèle la couleur spécifiée
|
|
||||||
elif action == 31:
|
|
||||||
x = raw_input("abscisses(x) [0]: ")
|
|
||||||
y = raw_input("ordonnées(y) [0]: ")
|
|
||||||
arg1, arg2 = 0,0
|
|
||||||
if x != "":
|
|
||||||
arg1 = int(x)
|
|
||||||
if y != "":
|
|
||||||
arg2 = int(y)
|
|
||||||
print startStr
|
|
||||||
colorShape(image1, arg1, arg2) # colorie la forme contenant le pixel de coordonnées donné
|
|
||||||
elif action == 32:
|
|
||||||
print startStr
|
|
||||||
colorAllShapes(image1) # colorie la forme contenant le pixel de coordonnées donné
|
|
||||||
elif action == 33:
|
|
||||||
print startStr
|
|
||||||
testStroke(image1) # trace les contours uniquement à partir de formes pleines
|
|
||||||
|
|
||||||
|
|
||||||
# filtres
|
|
||||||
elif action == 40:
|
|
||||||
print startStr
|
|
||||||
testAverageFilter(image1) # teste le lissage
|
|
||||||
elif action == 41:
|
|
||||||
print startStr
|
|
||||||
testLaplace(image1) # teste le filtre de Laplace
|
|
||||||
elif action == 42:
|
|
||||||
print startStr
|
|
||||||
testRoberts(image1) # teste le filtre de Roberts
|
|
||||||
elif action == 43:
|
|
||||||
print startStr
|
|
||||||
testPrewitt(image1) # teste le filtre de Prewitt
|
|
||||||
elif action == 44:
|
|
||||||
print startStr
|
|
||||||
testSobel(image1) # teste le filtre de Sobel
|
|
||||||
elif action == 45:
|
|
||||||
print startStr
|
|
||||||
testConvolution(image1) # teste le filtre de Convolution
|
|
||||||
elif action == 46:
|
|
||||||
print startStr
|
|
||||||
testBichrome(image1) # teste le passage au bichromatique
|
|
||||||
elif action == 47:
|
|
||||||
print startStr
|
|
||||||
testHighPass(image1) # teste le filtre passe haut
|
|
||||||
|
|
||||||
else:
|
|
||||||
print "Wrong choice"
|
|
||||||
exit();
|
|
||||||
|
|
||||||
print "+---------------------------+---------+"
|
|
||||||
print "| EXECUTION TIME | %s |" % execTime.get()
|
|
||||||
print "+---------------------------+---------+"
|
|
||||||
print
|
|
||||||
print result
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
raw_input('- [PRESS ANY KEY TO EXIT] -');
|
|
||||||
|
|
BIN
code/new.bmp
Before Width: | Height: | Size: 257 KiB After Width: | Height: | Size: 227 KiB |
After Width: | Height: | Size: 227 KiB |
370
code/tests.py
|
@ -498,24 +498,24 @@ def testAdditiveGaussianNoise(img, sigma=10, seuil=35):
|
||||||
# Parse A et B
|
# Parse A et B
|
||||||
# Compare A et B
|
# Compare A et B
|
||||||
# Affiche le pourcentage de ressemblance/différence
|
# Affiche le pourcentage de ressemblance/différence
|
||||||
def printImageQuality():
|
def printImageQuality(image, model):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
imageFile, modelFile = "", ""
|
# imageFile, modelFile = "", ""
|
||||||
|
|
||||||
|
|
||||||
# lecture des fichiers
|
# lecture des fichiers
|
||||||
print "| Reading files |",; t.reset();
|
# print "| Reading files |",; t.reset();
|
||||||
with open( sys.argv[1] ) as f:
|
# with open( sys.argv[1] ) as f:
|
||||||
imageFile = f.read();
|
# imageFile = f.read();
|
||||||
with open( sys.argv[2] ) as f:
|
# with open( sys.argv[2] ) as f:
|
||||||
modelFile = f.read();
|
# modelFile = f.read();
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
# parsage
|
# # parsage
|
||||||
print "| Parsing images |",; t.reset();
|
# print "| Parsing images |",; t.reset();
|
||||||
image = BMPFile(); image.parse( imageFile );
|
# image = BMPFile(); image.parse( imageFile );
|
||||||
model = BMPFile(); model.parse( modelFile );
|
# model = BMPFile(); model.parse( modelFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
# condition
|
# condition
|
||||||
imagePixelCount = image.header.width * image.header.height
|
imagePixelCount = image.header.width * image.header.height
|
||||||
|
@ -555,24 +555,24 @@ def printImageQuality():
|
||||||
# Parse A et B
|
# Parse A et B
|
||||||
# Calcule le SNR de A et B
|
# Calcule le SNR de A et B
|
||||||
# Affiche le pourcentage de ressemblance/différence
|
# Affiche le pourcentage de ressemblance/différence
|
||||||
def printSNR():
|
def printSNR(image, model):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
imageFile, modelFile = "", ""
|
# imageFile, modelFile = "", ""
|
||||||
|
|
||||||
|
|
||||||
# lecture des fichiers
|
# # lecture des fichiers
|
||||||
print "| Reading files |",; t.reset();
|
# print "| Reading files |",; t.reset();
|
||||||
with open( sys.argv[1] ) as f:
|
# with open( sys.argv[1] ) as f:
|
||||||
modelFile = f.read();
|
# modelFile = f.read();
|
||||||
with open( sys.argv[2] ) as f:
|
# with open( sys.argv[2] ) as f:
|
||||||
imageFile = f.read();
|
# imageFile = f.read();
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
# parsage
|
# # parsage
|
||||||
print "| Parsing images |",; t.reset();
|
# print "| Parsing images |",; t.reset();
|
||||||
model = BMPFile(); model.parse( modelFile );
|
# model = BMPFile(); model.parse( modelFile );
|
||||||
image = BMPFile(); image.parse( imageFile );
|
# image = BMPFile(); image.parse( imageFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
# condition
|
# condition
|
||||||
modelPixelCount = model.header.width * model.header.height
|
modelPixelCount = model.header.width * model.header.height
|
||||||
|
@ -615,25 +615,26 @@ def printSNR():
|
||||||
# Parse A et B
|
# Parse A et B
|
||||||
# Créer une matrice de pixels
|
# Créer une matrice de pixels
|
||||||
# Unparse cette matrice et l'enregistre dans le fichier "compare.bmp"
|
# Unparse cette matrice et l'enregistre dans le fichier "compare.bmp"
|
||||||
def imageForImageQuality():
|
def imageForImageQuality(imgae1, image2):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
imageFile, modelFile = "", ""
|
# imageFile, modelFile = "", ""
|
||||||
image, model, newImg = BMPFile(), BMPFile(), BMPFile()
|
# image, model = BMPFile(), BMPFile()
|
||||||
|
newImg = BMPFile()
|
||||||
|
|
||||||
|
|
||||||
# lecture des fichiers
|
# # lecture des fichiers
|
||||||
print "| Reading files |",; t.reset();
|
# print "| Reading files |",; t.reset();
|
||||||
with open( sys.argv[1] ) as f:
|
# with open( sys.argv[1] ) as f:
|
||||||
imageFile = f.read();
|
# imageFile = f.read();
|
||||||
with open( sys.argv[2] ) as f:
|
# with open( sys.argv[2] ) as f:
|
||||||
modelFile = f.read();
|
# modelFile = f.read();
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
# parsage
|
# # parsage
|
||||||
print "| Parsing images |",; t.reset();
|
# print "| Parsing images |",; t.reset();
|
||||||
image.parse( imageFile );
|
# image.parse( imageFile );
|
||||||
model.parse( modelFile );
|
# model.parse( modelFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
# condition
|
# condition
|
||||||
imagePixelCount = image.header.width * image.header.height
|
imagePixelCount = image.header.width * image.header.height
|
||||||
|
@ -685,25 +686,25 @@ def imageForImageQuality():
|
||||||
# Parse les fichiers A et B
|
# Parse les fichiers A et B
|
||||||
# Créer la matrice de pixels à partir de l'addition de A et B
|
# Créer la matrice de pixels à partir de l'addition de A et B
|
||||||
# Unparse le tout et l'enregistre dans mergeAdd.bmp
|
# Unparse le tout et l'enregistre dans mergeAdd.bmp
|
||||||
def mergeImagesAdditive():
|
def mergeImagesAdditive(A, B):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
imageFile, modelFile = "", ""
|
# imageFile, modelFile = "", ""
|
||||||
A, B, newImg = BMPFile(), BMPFile(), BMPFile()
|
# A, B = BMPFile(), BMPFile()
|
||||||
|
newImg = BMPFile()
|
||||||
|
|
||||||
# lecture des fichiers
|
# lecture des fichiers
|
||||||
print "| Reading files |",; t.reset();
|
# print "| Reading files |",; t.reset();
|
||||||
with open( sys.argv[1] ) as f:
|
# with open( sys.argv[1] ) as f:
|
||||||
AFile = f.read();
|
# AFile = f.read();
|
||||||
with open( sys.argv[2] ) as f:
|
# with open( sys.argv[2] ) as f:
|
||||||
BFile = f.read();
|
# BFile = f.read();
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
# parsage
|
# # parsage
|
||||||
print "| Parsing images |",; t.reset();
|
# print "| Parsing images |",; t.reset();
|
||||||
A.parse( AFile );
|
# A.parse( AFile );
|
||||||
B.parse( BFile );
|
# B.parse( BFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
# condition
|
# condition
|
||||||
|
@ -760,25 +761,25 @@ def mergeImagesAdditive():
|
||||||
# Parse les fichiers A et B
|
# Parse les fichiers A et B
|
||||||
# Créer la matrice de pixels à partir de l'addition de A et B
|
# Créer la matrice de pixels à partir de l'addition de A et B
|
||||||
# Unparse le tout et l'enregistre dans mergeSub.bmp
|
# Unparse le tout et l'enregistre dans mergeSub.bmp
|
||||||
def mergeImagesSubstractive():
|
def mergeImagesSubstractive(A, B):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
imageFile, modelFile = "", ""
|
# imageFile, modelFile = "", ""
|
||||||
A, B, newImg = BMPFile(), BMPFile(), BMPFile()
|
# A, B = BMPFile(), BMPFile()
|
||||||
|
newImg = BMPFile()
|
||||||
|
|
||||||
# lecture des fichiers
|
# lecture des fichiers
|
||||||
print "| Reading files |",; t.reset();
|
# print "| Reading files |",; t.reset();
|
||||||
with open( sys.argv[1] ) as f:
|
# with open( sys.argv[1] ) as f:
|
||||||
AFile = f.read();
|
# AFile = f.read();
|
||||||
with open( sys.argv[2] ) as f:
|
# with open( sys.argv[2] ) as f:
|
||||||
BFile = f.read();
|
# BFile = f.read();
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
# parsage
|
# # parsage
|
||||||
print "| Parsing images |",; t.reset();
|
# print "| Parsing images |",; t.reset();
|
||||||
A.parse( AFile );
|
# A.parse( AFile );
|
||||||
B.parse( BFile );
|
# B.parse( BFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
# condition
|
# condition
|
||||||
|
@ -845,9 +846,9 @@ def mergeImagesSubstractive():
|
||||||
# Parse le fichier d'entrée
|
# Parse le fichier d'entrée
|
||||||
# colore l'image
|
# colore l'image
|
||||||
# Unparse le tout et l'enregistre dans le fichier de sortie
|
# Unparse le tout et l'enregistre dans le fichier de sortie
|
||||||
def revealShapes(red=0,green=0,blue=0, seuil=50):
|
def revealShapes(img, red=0,green=0,blue=0, seuil=50):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
img = BMPFile()
|
# img = BMPFile()
|
||||||
|
|
||||||
rMin, rMax = red-seuil, red+seuil
|
rMin, rMax = red-seuil, red+seuil
|
||||||
gMin, gMax = green-seuil, green+seuil
|
gMin, gMax = green-seuil, green+seuil
|
||||||
|
@ -855,15 +856,15 @@ def revealShapes(red=0,green=0,blue=0, seuil=50):
|
||||||
|
|
||||||
|
|
||||||
# lecture du fichier
|
# lecture du fichier
|
||||||
print "| Reading file |",; t.reset();
|
# print "| Reading file |",; t.reset();
|
||||||
with open( sys.argv[1] ) as f:
|
# with open( sys.argv[1] ) as f:
|
||||||
binFile = f.read();
|
# binFile = f.read();
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
# parsage
|
# # parsage
|
||||||
print "| Parsing image |",; t.reset();
|
# print "| Parsing image |",; t.reset();
|
||||||
img.parse( binFile );
|
# img.parse( binFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
# coloration
|
# coloration
|
||||||
|
@ -875,6 +876,7 @@ def revealShapes(red=0,green=0,blue=0, seuil=50):
|
||||||
pixel.setRGB(255,255,255) # on colore en blanc
|
pixel.setRGB(255,255,255) # on colore en blanc
|
||||||
else:
|
else:
|
||||||
pixel.setRGB(0,0,0) # sinon on colore en noir
|
pixel.setRGB(0,0,0) # sinon on colore en noir
|
||||||
|
img.drawer.setPixel( pixel );
|
||||||
print "%s |" % (t.get())
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
print "| Unparsing |",; t.reset();
|
print "| Unparsing |",; t.reset();
|
||||||
|
@ -899,20 +901,20 @@ def revealShapes(red=0,green=0,blue=0, seuil=50):
|
||||||
# Parse le fichier d'entrée
|
# Parse le fichier d'entrée
|
||||||
# colore la forme
|
# colore la forme
|
||||||
# Unparse le tout et l'enregistre dans le fichier de sortie
|
# Unparse le tout et l'enregistre dans le fichier de sortie
|
||||||
def colorShape(x=0, y=0):
|
def colorShape(img, x=0, y=0):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
img = BMPFile()
|
# img = BMPFile()
|
||||||
|
|
||||||
# lecture du fichier
|
# # lecture du fichier
|
||||||
print "| Reading file |",; t.reset();
|
# print "| Reading file |",; t.reset();
|
||||||
with open( sys.argv[1] ) as f:
|
# with open( sys.argv[1] ) as f:
|
||||||
binFile = f.read();
|
# binFile = f.read();
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
# parsage
|
# # parsage
|
||||||
print "| Parsing image |",; t.reset();
|
# print "| Parsing image |",; t.reset();
|
||||||
img.parse( binFile );
|
# img.parse( binFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -927,7 +929,8 @@ def colorShape(x=0, y=0):
|
||||||
|
|
||||||
# récupère la forme
|
# récupère la forme
|
||||||
print "| Getting shape |",; t.reset();
|
print "| Getting shape |",; t.reset();
|
||||||
shape = FX.Shape.getShape(img.content.map[y][x], img.content.map)
|
shape = FX.Shape.getShape(img.drawer, img.content.map[y][x], img.content.map)
|
||||||
|
img.drawer.refresh();
|
||||||
|
|
||||||
# on colorie la forme en rouge
|
# on colorie la forme en rouge
|
||||||
for pixel in shape:
|
for pixel in shape:
|
||||||
|
@ -963,20 +966,20 @@ def colorShape(x=0, y=0):
|
||||||
# Parse le fichier d'entrée
|
# Parse le fichier d'entrée
|
||||||
# colore les formes
|
# colore les formes
|
||||||
# Unparse le tout et l'enregistre dans le fichier de sortie
|
# Unparse le tout et l'enregistre dans le fichier de sortie
|
||||||
def colorAllShapes():
|
def colorAllShapes(img):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
img = BMPFile()
|
# img = BMPFile()
|
||||||
|
|
||||||
# lecture du fichier
|
# # lecture du fichier
|
||||||
print "| Reading file |",; t.reset();
|
# print "| Reading file |",; t.reset();
|
||||||
with open( sys.argv[1] ) as f:
|
# with open( sys.argv[1] ) as f:
|
||||||
binFile = f.read();
|
# binFile = f.read();
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
# parsage
|
# # parsage
|
||||||
print "| Parsing image |",; t.reset();
|
# print "| Parsing image |",; t.reset();
|
||||||
img.parse( binFile );
|
# img.parse( binFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -988,7 +991,7 @@ def colorAllShapes():
|
||||||
for pixel in line:
|
for pixel in line:
|
||||||
# condition (si ce n'est pas le fond ~= noir)
|
# condition (si ce n'est pas le fond ~= noir)
|
||||||
if pixel.r + pixel.g + pixel.b > 3*100 and pixel not in already: # si loin du noir
|
if pixel.r + pixel.g + pixel.b > 3*100 and pixel not in already: # si loin du noir
|
||||||
shape = FX.Shape.getShape(pixel, img.content.map)
|
shape = FX.Shape.getShape(img.drawer, pixel, img.content.map)
|
||||||
print "shape detected"
|
print "shape detected"
|
||||||
R, G, B = random.randint(0,255), random.randint(0,255), random.randint(0,255)
|
R, G, B = random.randint(0,255), random.randint(0,255), random.randint(0,255)
|
||||||
|
|
||||||
|
@ -1030,20 +1033,20 @@ def colorAllShapes():
|
||||||
# récupère les contours
|
# récupère les contours
|
||||||
# trace les contours
|
# trace les contours
|
||||||
# Unparse le tout et l'enregistre dans le fichier de sortie
|
# Unparse le tout et l'enregistre dans le fichier de sortie
|
||||||
def testStroke():
|
def testStroke(img):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
img = BMPFile()
|
# img = BMPFile()
|
||||||
|
|
||||||
# lecture du fichier
|
# lecture du fichier
|
||||||
print "| Reading file |",; t.reset();
|
# print "| Reading file |",; t.reset();
|
||||||
with open( sys.argv[1] ) as f:
|
# with open( sys.argv[1] ) as f:
|
||||||
binFile = f.read();
|
# binFile = f.read();
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
# parsage
|
# # parsage
|
||||||
print "| Parsing image |",; t.reset();
|
# print "| Parsing image |",; t.reset();
|
||||||
img.parse( binFile );
|
# img.parse( binFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
strokes = []
|
strokes = []
|
||||||
|
@ -1058,6 +1061,7 @@ def testStroke():
|
||||||
pixel.setRGB(255,255,255)
|
pixel.setRGB(255,255,255)
|
||||||
else:
|
else:
|
||||||
pixel.setRGB(0,0,0)
|
pixel.setRGB(0,0,0)
|
||||||
|
img.drawer.setPixel( pixel );
|
||||||
print "%s |" % (t.get())
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
|
@ -1095,28 +1099,28 @@ def testStroke():
|
||||||
# Parse le fichier d'origine
|
# Parse le fichier d'origine
|
||||||
# Applique le filtre
|
# Applique le filtre
|
||||||
# Unparse l'image et l'enregistre dans le fichier de sortie
|
# Unparse l'image et l'enregistre dans le fichier de sortie
|
||||||
def testAverageFilter():
|
def testAverageFilter(img):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
|
|
||||||
|
|
||||||
# lecture du fichier
|
# lecture du fichier
|
||||||
print "| Reading Image |",; t.reset();
|
# print "| Reading Image |",; t.reset();
|
||||||
with open( sys.argv[1] ) as file:
|
# with open( sys.argv[1] ) as file:
|
||||||
binFile = file.read()
|
# binFile = file.read()
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
img = BMPFile(); # Instanciation du BMPFile
|
# img = BMPFile(); # Instanciation du BMPFile
|
||||||
|
|
||||||
|
|
||||||
# Parsing
|
# # Parsing
|
||||||
print "| Parsing file |",; t.reset();
|
# print "| Parsing file |",; t.reset();
|
||||||
img.parse( binFile );
|
# img.parse( binFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
print "| Filtre moyen |",; t.reset();
|
print "| Filtre moyen |",; t.reset();
|
||||||
img.content.map = FX.Filter.averageFilter(img.content.map)
|
img.content.map = FX.Filter.averageFilter(img.drawer, img.content.map)
|
||||||
print "%s |" % (t.get())
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
# Unparsing
|
# Unparsing
|
||||||
|
@ -1150,28 +1154,28 @@ def testAverageFilter():
|
||||||
# Parse le fichier d'origine
|
# Parse le fichier d'origine
|
||||||
# Applique le filtre
|
# Applique le filtre
|
||||||
# Unparse l'image et l'enregistre dans le fichier de sortie
|
# Unparse l'image et l'enregistre dans le fichier de sortie
|
||||||
def testLaplace():
|
def testLaplace(img):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
|
|
||||||
|
|
||||||
# lecture du fichier
|
# # lecture du fichier
|
||||||
print "| Reading Image |",; t.reset();
|
# print "| Reading Image |",; t.reset();
|
||||||
with open( sys.argv[1] ) as file:
|
# with open( sys.argv[1] ) as file:
|
||||||
binFile = file.read()
|
# binFile = file.read()
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
img = BMPFile(); # Instanciation du BMPFile
|
# img = BMPFile(); # Instanciation du BMPFile
|
||||||
|
|
||||||
|
|
||||||
# Parsing
|
# # Parsing
|
||||||
print "| Parsing file |",; t.reset();
|
# print "| Parsing file |",; t.reset();
|
||||||
img.parse( binFile );
|
# img.parse( binFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
print "| Application du filtre |",; t.reset();
|
print "| Application du filtre |",; t.reset();
|
||||||
img.content.map = FX.Filter.Laplace(img.content.map);
|
img.content.map = FX.Filter.Laplace(img.drawer, img.content.map);
|
||||||
print "%s |" % (t.get())
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
# Unparsing
|
# Unparsing
|
||||||
|
@ -1195,28 +1199,28 @@ def testLaplace():
|
||||||
# Parse le fichier d'origine
|
# Parse le fichier d'origine
|
||||||
# Applique le filtre
|
# Applique le filtre
|
||||||
# Unparse l'image et l'enregistre dans le fichier de sortie
|
# Unparse l'image et l'enregistre dans le fichier de sortie
|
||||||
def testRoberts():
|
def testRoberts(img):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
|
|
||||||
|
|
||||||
# lecture du fichier
|
# lecture du fichier
|
||||||
print "| Reading Image |",; t.reset();
|
# print "| Reading Image |",; t.reset();
|
||||||
with open( sys.argv[1] ) as file:
|
# with open( sys.argv[1] ) as file:
|
||||||
binFile = file.read()
|
# binFile = file.read()
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
img = BMPFile(); # Instanciation du BMPFile
|
# img = BMPFile(); # Instanciation du BMPFile
|
||||||
|
|
||||||
|
|
||||||
# Parsing
|
# # Parsing
|
||||||
print "| Parsing file |",; t.reset();
|
# print "| Parsing file |",; t.reset();
|
||||||
img.parse( binFile );
|
# img.parse( binFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
print "| Application du filtre |",; t.reset();
|
print "| Application du filtre |",; t.reset();
|
||||||
img.content.map = FX.Filter.Roberts(img.content.map);
|
img.content.map = FX.Filter.Roberts(img.drawer, img.content.map);
|
||||||
print "%s |" % (t.get())
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
# Unparsing
|
# Unparsing
|
||||||
|
@ -1243,28 +1247,28 @@ def testRoberts():
|
||||||
# Parse le fichier d'origine
|
# Parse le fichier d'origine
|
||||||
# Applique le filtre
|
# Applique le filtre
|
||||||
# Unparse l'image et l'enregistre dans le fichier de sortie
|
# Unparse l'image et l'enregistre dans le fichier de sortie
|
||||||
def testPrewitt():
|
def testPrewitt(img):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
|
|
||||||
|
|
||||||
# lecture du fichier
|
# lecture du fichier
|
||||||
print "| Reading Image |",; t.reset();
|
# print "| Reading Image |",; t.reset();
|
||||||
with open( sys.argv[1] ) as file:
|
# with open( sys.argv[1] ) as file:
|
||||||
binFile = file.read()
|
# binFile = file.read()
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
img = BMPFile(); # Instanciation du BMPFile
|
# img = BMPFile(); # Instanciation du BMPFile
|
||||||
|
|
||||||
|
|
||||||
# Parsing
|
# # Parsing
|
||||||
print "| Parsing file |",; t.reset();
|
# print "| Parsing file |",; t.reset();
|
||||||
img.parse( binFile );
|
# img.parse( binFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
print "| Application du filtre |",; t.reset();
|
print "| Application du filtre |",; t.reset();
|
||||||
FX.Filter.Prewitt(img.content.map);
|
FX.Filter.Prewitt(img.drawer, img.content.map);
|
||||||
print "%s |" % (t.get())
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
# Unparsing
|
# Unparsing
|
||||||
|
@ -1293,28 +1297,28 @@ def testPrewitt():
|
||||||
# Parse le fichier d'origine
|
# Parse le fichier d'origine
|
||||||
# Applique le filtre
|
# Applique le filtre
|
||||||
# Unparse l'image et l'enregistre dans le fichier de sortie
|
# Unparse l'image et l'enregistre dans le fichier de sortie
|
||||||
def testSobel():
|
def testSobel(img):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
|
|
||||||
|
|
||||||
# lecture du fichier
|
# lecture du fichier
|
||||||
print "| Reading Image |",; t.reset();
|
# print "| Reading Image |",; t.reset();
|
||||||
with open( sys.argv[1] ) as file:
|
# with open( sys.argv[1] ) as file:
|
||||||
binFile = file.read()
|
# binFile = file.read()
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
img = BMPFile(); # Instanciation du BMPFile
|
# img = BMPFile(); # Instanciation du BMPFile
|
||||||
|
|
||||||
|
|
||||||
# Parsing
|
# # Parsing
|
||||||
print "| Parsing file |",; t.reset();
|
# print "| Parsing file |",; t.reset();
|
||||||
img.parse( binFile );
|
# img.parse( binFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
print "| Application du filtre |",; t.reset();
|
print "| Application du filtre |",; t.reset();
|
||||||
img.content.map = FX.Filter.Sobel(img.content.map);
|
img.content.map = FX.Filter.Sobel(img.drawer, img.content.map);
|
||||||
print "%s |" % (t.get())
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
# Unparsing
|
# Unparsing
|
||||||
|
@ -1346,24 +1350,24 @@ def testSobel():
|
||||||
# Parse le fichier d'origine
|
# Parse le fichier d'origine
|
||||||
# Applique le filtre
|
# Applique le filtre
|
||||||
# Unparse l'image et l'enregistre dans le fichier de sortie
|
# Unparse l'image et l'enregistre dans le fichier de sortie
|
||||||
def testConvolution():
|
def testConvolution(img):
|
||||||
t = Timer();
|
t = Timer();
|
||||||
|
|
||||||
|
|
||||||
# lecture du fichier
|
# lecture du fichier
|
||||||
print "| Reading Image |",; t.reset();
|
# print "| Reading Image |",; t.reset();
|
||||||
with open( sys.argv[1] ) as file:
|
# with open( sys.argv[1] ) as file:
|
||||||
binFile = file.read()
|
# binFile = file.read()
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
|
|
||||||
img = BMPFile(); # Instanciation du BMPFile
|
# img = BMPFile(); # Instanciation du BMPFile
|
||||||
|
|
||||||
|
|
||||||
# Parsing
|
# # Parsing
|
||||||
print "| Parsing file |",; t.reset();
|
# print "| Parsing file |",; t.reset();
|
||||||
img.parse( binFile );
|
# img.parse( binFile );
|
||||||
print "%s |" % (t.get())
|
# print "%s |" % (t.get())
|
||||||
|
|
||||||
kernel = [
|
kernel = [
|
||||||
[ 4, 3, 2, 3, 4],
|
[ 4, 3, 2, 3, 4],
|
||||||
|
@ -1374,7 +1378,7 @@ def testConvolution():
|
||||||
]
|
]
|
||||||
|
|
||||||
print "| Application du filtre |",; t.reset();
|
print "| Application du filtre |",; t.reset();
|
||||||
img.content.map = FX.Filter.Convolution(img.content.map, kernel);
|
img.content.map = FX.Filter.Convolution(img.drawer, img.content.map, kernel);
|
||||||
print "%s |" % (t.get())
|
print "%s |" % (t.get())
|
||||||
|
|
||||||
# Unparsing
|
# Unparsing
|
||||||
|
|
|
@ -41,7 +41,7 @@ class Filter:
|
||||||
# 0 -1
|
# 0 -1
|
||||||
#
|
#
|
||||||
def Roberts(self, drawer, pixelMap):
|
def Roberts(self, drawer, pixelMap):
|
||||||
return self.Convolution(pixelMap, kernel=[
|
return self.Convolution(drawer, pixelMap, kernel=[
|
||||||
[1, 0],
|
[1, 0],
|
||||||
[0, -1]
|
[0, -1]
|
||||||
] );
|
] );
|
||||||
|
@ -58,7 +58,7 @@ class Filter:
|
||||||
# -1 -1 -1
|
# -1 -1 -1
|
||||||
#
|
#
|
||||||
def Laplace(self, drawer, pixelMap):
|
def Laplace(self, drawer, pixelMap):
|
||||||
return self.Convolution(pixelMap, kernel=[
|
return self.Convolution(drawer, pixelMap, kernel=[
|
||||||
[-1, -1, -1],
|
[-1, -1, -1],
|
||||||
[-1, 8, -1],
|
[-1, 8, -1],
|
||||||
[-1, -1, -1]
|
[-1, -1, -1]
|
||||||
|
@ -77,7 +77,7 @@ class Filter:
|
||||||
# -1 0 1
|
# -1 0 1
|
||||||
#
|
#
|
||||||
def Sobel(self, drawer, pixelMap):
|
def Sobel(self, drawer, pixelMap):
|
||||||
return self.Convolution(pixelMap, kernel=[
|
return self.Convolution(drawer, pixelMap, kernel=[
|
||||||
[-1, 0, 1],
|
[-1, 0, 1],
|
||||||
[-2, 0, 2],
|
[-2, 0, 2],
|
||||||
[-1, 0, 1]
|
[-1, 0, 1]
|
||||||
|
@ -96,7 +96,7 @@ class Filter:
|
||||||
# -1 0 1
|
# -1 0 1
|
||||||
#
|
#
|
||||||
def HighPass(self, drawer, pixelMap):
|
def HighPass(self, drawer, pixelMap):
|
||||||
return self.Convolution(pixelMap, kernel=[
|
return self.Convolution(drawer, pixelMap, kernel=[
|
||||||
[ 0, -1, 0],
|
[ 0, -1, 0],
|
||||||
[-1, 5, -1],
|
[-1, 5, -1],
|
||||||
[ 0, -1, 0]
|
[ 0, -1, 0]
|
||||||
|
|
|
@ -4,6 +4,11 @@ import random
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
import sys
|
||||||
|
sys.path.append(sys.path[0]+'/..')
|
||||||
|
from BMPFile import RGBPixel
|
||||||
|
|
||||||
|
|
||||||
class Shape:
|
class Shape:
|
||||||
# récupère la forme complète autour du pixel donné #
|
# récupère la forme complète autour du pixel donné #
|
||||||
####################################################
|
####################################################
|
||||||
|
@ -13,7 +18,7 @@ class Shape:
|
||||||
#
|
#
|
||||||
# @return retourne la liste des pixels composant la forme (références)
|
# @return retourne la liste des pixels composant la forme (références)
|
||||||
#
|
#
|
||||||
def getShape(self, originalPixel, pixelMap, seuil=10):
|
def getShape(self, drawer, originalPixel, pixelMap, seuil=10):
|
||||||
width = len( pixelMap[0] )
|
width = len( pixelMap[0] )
|
||||||
height = len( pixelMap )
|
height = len( pixelMap )
|
||||||
|
|
||||||
|
@ -23,6 +28,16 @@ class Shape:
|
||||||
# on continue d'analyser tant qu'il y a des pixels à traiter
|
# on continue d'analyser tant qu'il y a des pixels à traiter
|
||||||
while len(waiting) > 0:
|
while len(waiting) > 0:
|
||||||
pixel = waiting[0]
|
pixel = waiting[0]
|
||||||
|
pixel.done = True;
|
||||||
|
|
||||||
|
drawer.setPixel( RGBPixel(
|
||||||
|
r = 255,
|
||||||
|
g = 0,
|
||||||
|
b = 0,
|
||||||
|
x = pixel.x,
|
||||||
|
y = pixel.y,
|
||||||
|
bpp = pixel.bpp
|
||||||
|
));
|
||||||
|
|
||||||
# on ajoute le pixel à la forme
|
# on ajoute le pixel à la forme
|
||||||
shape.append( pixel )
|
shape.append( pixel )
|
||||||
|
@ -56,7 +71,8 @@ class Shape:
|
||||||
# si le pixel n'a pas une couleur trop éloignée du pixel central
|
# si le pixel n'a pas une couleur trop éloignée du pixel central
|
||||||
if abs(pixel.r-currentP.r) <= seuil and abs(pixel.g-currentP.g) <= seuil and abs(pixel.b-currentP.b) <= seuil:
|
if abs(pixel.r-currentP.r) <= seuil and abs(pixel.g-currentP.g) <= seuil and abs(pixel.b-currentP.b) <= seuil:
|
||||||
# on ajoute le pixel à la liste d'attente
|
# on ajoute le pixel à la liste d'attente
|
||||||
if not( currentP in shape or currentP in waiting):
|
if currentP not in shape and currentP not in waiting:
|
||||||
|
# if currentP.done == False:
|
||||||
waiting.append( currentP )
|
waiting.append( currentP )
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,6 +158,8 @@ class Shape:
|
||||||
# on définit le kernel
|
# on définit le kernel
|
||||||
k = getKernel(master, position)
|
k = getKernel(master, position)
|
||||||
|
|
||||||
|
pixel = k[position];
|
||||||
|
|
||||||
# on vide la liste des esclaves
|
# on vide la liste des esclaves
|
||||||
slaves = []
|
slaves = []
|
||||||
|
|
||||||
|
|