Ajout de la possibilté de recharger l'image ou d'enchaîner les actions

This commit is contained in:
xdrm-brackets 2015-10-12 19:35:42 +02:00
parent 630cdce310
commit e060a0888c
10 changed files with 470 additions and 408 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 257 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 257 KiB

View File

@ -304,6 +304,8 @@ class BMPContent:
#################################
class RGBPixel:
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 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
@ -328,8 +330,8 @@ class RGBPixel:
self.intData = [ int( (r+g+b) / 3 ) ]
self.binData = chr( self.intData[0] )
else:
self.intData = [ r, g, b ]
self.binData = chr(g) + chr(b) + chr(r)
self.intData = [ b, g, r ]
self.binData = chr(b) + chr(g) + chr(r)
def setRGB(self, r=0, g=0, b=0, x=None, y=None, bpp=24):

Binary file not shown.

Before

Width:  |  Height:  |  Size: 257 KiB

After

Width:  |  Height:  |  Size: 227 KiB

View File

@ -10,6 +10,7 @@ from tests import *
import random
import sys
from os import system as sh
import time
# test par défaut puis quitte
@ -25,235 +26,272 @@ if len(sys.argv) < 3:
################" 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 "| TRAITEMENT D'IMAGE |"
print "| CHARGEMENT... |"
print "| |"
print "+---------------------------+"
# ON CREE LES IMAGES
image1 = BMPFile();
image2 = BMPFile();
image1, file1 = BMPFile(), "";
image2, file2 = BMPFile(), "";
with open( sys.argv[1] ) as file:
image1.parse( 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)
file1 += file.read();
with open( sys.argv[2] ) as file:
image2.parse( file.read() )
print "| <out> %s |" % exactLength( sys.argv[2], 19, -1)
file2 += file.read()
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 "+---------------------------+"
# 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] -');
interfaceLoop();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 257 KiB

After

Width:  |  Height:  |  Size: 227 KiB

BIN
code/new2.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 KiB

View File

@ -498,24 +498,24 @@ def testAdditiveGaussianNoise(img, sigma=10, seuil=35):
# Parse A et B
# Compare A et B
# Affiche le pourcentage de ressemblance/différence
def printImageQuality():
def printImageQuality(image, model):
t = Timer();
imageFile, modelFile = "", ""
# imageFile, modelFile = "", ""
# lecture des fichiers
print "| Reading files |",; t.reset();
with open( sys.argv[1] ) as f:
imageFile = f.read();
with open( sys.argv[2] ) as f:
modelFile = f.read();
print "%s |" % (t.get())
# print "| Reading files |",; t.reset();
# with open( sys.argv[1] ) as f:
# imageFile = f.read();
# with open( sys.argv[2] ) as f:
# modelFile = f.read();
# print "%s |" % (t.get())
# parsage
print "| Parsing images |",; t.reset();
image = BMPFile(); image.parse( imageFile );
model = BMPFile(); model.parse( modelFile );
print "%s |" % (t.get())
# # parsage
# print "| Parsing images |",; t.reset();
# image = BMPFile(); image.parse( imageFile );
# model = BMPFile(); model.parse( modelFile );
# print "%s |" % (t.get())
# condition
imagePixelCount = image.header.width * image.header.height
@ -555,24 +555,24 @@ def printImageQuality():
# Parse A et B
# Calcule le SNR de A et B
# Affiche le pourcentage de ressemblance/différence
def printSNR():
def printSNR(image, model):
t = Timer();
imageFile, modelFile = "", ""
# imageFile, modelFile = "", ""
# lecture des fichiers
print "| Reading files |",; t.reset();
with open( sys.argv[1] ) as f:
modelFile = f.read();
with open( sys.argv[2] ) as f:
imageFile = f.read();
print "%s |" % (t.get())
# # lecture des fichiers
# print "| Reading files |",; t.reset();
# with open( sys.argv[1] ) as f:
# modelFile = f.read();
# with open( sys.argv[2] ) as f:
# imageFile = f.read();
# print "%s |" % (t.get())
# parsage
print "| Parsing images |",; t.reset();
model = BMPFile(); model.parse( modelFile );
image = BMPFile(); image.parse( imageFile );
print "%s |" % (t.get())
# # parsage
# print "| Parsing images |",; t.reset();
# model = BMPFile(); model.parse( modelFile );
# image = BMPFile(); image.parse( imageFile );
# print "%s |" % (t.get())
# condition
modelPixelCount = model.header.width * model.header.height
@ -615,25 +615,26 @@ def printSNR():
# Parse A et B
# Créer une matrice de pixels
# Unparse cette matrice et l'enregistre dans le fichier "compare.bmp"
def imageForImageQuality():
def imageForImageQuality(imgae1, image2):
t = Timer();
imageFile, modelFile = "", ""
image, model, newImg = BMPFile(), BMPFile(), BMPFile()
# imageFile, modelFile = "", ""
# image, model = BMPFile(), BMPFile()
newImg = BMPFile()
# lecture des fichiers
print "| Reading files |",; t.reset();
with open( sys.argv[1] ) as f:
imageFile = f.read();
with open( sys.argv[2] ) as f:
modelFile = f.read();
print "%s |" % (t.get())
# # lecture des fichiers
# print "| Reading files |",; t.reset();
# with open( sys.argv[1] ) as f:
# imageFile = f.read();
# with open( sys.argv[2] ) as f:
# modelFile = f.read();
# print "%s |" % (t.get())
# parsage
print "| Parsing images |",; t.reset();
image.parse( imageFile );
model.parse( modelFile );
print "%s |" % (t.get())
# # parsage
# print "| Parsing images |",; t.reset();
# image.parse( imageFile );
# model.parse( modelFile );
# print "%s |" % (t.get())
# condition
imagePixelCount = image.header.width * image.header.height
@ -685,25 +686,25 @@ def imageForImageQuality():
# Parse les fichiers 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
def mergeImagesAdditive():
def mergeImagesAdditive(A, B):
t = Timer();
imageFile, modelFile = "", ""
A, B, newImg = BMPFile(), BMPFile(), BMPFile()
# imageFile, modelFile = "", ""
# A, B = BMPFile(), BMPFile()
newImg = BMPFile()
# lecture des fichiers
print "| Reading files |",; t.reset();
with open( sys.argv[1] ) as f:
AFile = f.read();
with open( sys.argv[2] ) as f:
BFile = f.read();
print "%s |" % (t.get())
# print "| Reading files |",; t.reset();
# with open( sys.argv[1] ) as f:
# AFile = f.read();
# with open( sys.argv[2] ) as f:
# BFile = f.read();
# print "%s |" % (t.get())
# parsage
print "| Parsing images |",; t.reset();
A.parse( AFile );
B.parse( BFile );
print "%s |" % (t.get())
# # parsage
# print "| Parsing images |",; t.reset();
# A.parse( AFile );
# B.parse( BFile );
# print "%s |" % (t.get())
# condition
@ -760,25 +761,25 @@ def mergeImagesAdditive():
# Parse les fichiers 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
def mergeImagesSubstractive():
def mergeImagesSubstractive(A, B):
t = Timer();
imageFile, modelFile = "", ""
A, B, newImg = BMPFile(), BMPFile(), BMPFile()
# imageFile, modelFile = "", ""
# A, B = BMPFile(), BMPFile()
newImg = BMPFile()
# lecture des fichiers
print "| Reading files |",; t.reset();
with open( sys.argv[1] ) as f:
AFile = f.read();
with open( sys.argv[2] ) as f:
BFile = f.read();
print "%s |" % (t.get())
# print "| Reading files |",; t.reset();
# with open( sys.argv[1] ) as f:
# AFile = f.read();
# with open( sys.argv[2] ) as f:
# BFile = f.read();
# print "%s |" % (t.get())
# parsage
print "| Parsing images |",; t.reset();
A.parse( AFile );
B.parse( BFile );
print "%s |" % (t.get())
# # parsage
# print "| Parsing images |",; t.reset();
# A.parse( AFile );
# B.parse( BFile );
# print "%s |" % (t.get())
# condition
@ -845,9 +846,9 @@ def mergeImagesSubstractive():
# Parse le fichier d'entrée
# colore l'image
# 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();
img = BMPFile()
# img = BMPFile()
rMin, rMax = red-seuil, red+seuil
gMin, gMax = green-seuil, green+seuil
@ -855,15 +856,15 @@ def revealShapes(red=0,green=0,blue=0, seuil=50):
# lecture du fichier
print "| Reading file |",; t.reset();
with open( sys.argv[1] ) as f:
binFile = f.read();
print "%s |" % (t.get())
# print "| Reading file |",; t.reset();
# with open( sys.argv[1] ) as f:
# binFile = f.read();
# print "%s |" % (t.get())
# parsage
print "| Parsing image |",; t.reset();
img.parse( binFile );
print "%s |" % (t.get())
# # parsage
# print "| Parsing image |",; t.reset();
# img.parse( binFile );
# print "%s |" % (t.get())
# coloration
@ -875,6 +876,7 @@ def revealShapes(red=0,green=0,blue=0, seuil=50):
pixel.setRGB(255,255,255) # on colore en blanc
else:
pixel.setRGB(0,0,0) # sinon on colore en noir
img.drawer.setPixel( pixel );
print "%s |" % (t.get())
print "| Unparsing |",; t.reset();
@ -899,20 +901,20 @@ def revealShapes(red=0,green=0,blue=0, seuil=50):
# Parse le fichier d'entrée
# colore la forme
# 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();
img = BMPFile()
# img = BMPFile()
# lecture du fichier
print "| Reading file |",; t.reset();
with open( sys.argv[1] ) as f:
binFile = f.read();
print "%s |" % (t.get())
# # lecture du fichier
# print "| Reading file |",; t.reset();
# with open( sys.argv[1] ) as f:
# binFile = f.read();
# print "%s |" % (t.get())
# parsage
print "| Parsing image |",; t.reset();
img.parse( binFile );
print "%s |" % (t.get())
# # parsage
# print "| Parsing image |",; t.reset();
# img.parse( binFile );
# print "%s |" % (t.get())
@ -927,8 +929,9 @@ def colorShape(x=0, y=0):
# récupère la forme
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
for pixel in shape:
pixel.setRGB(255,0,0);
@ -963,20 +966,20 @@ def colorShape(x=0, y=0):
# Parse le fichier d'entrée
# colore les formes
# Unparse le tout et l'enregistre dans le fichier de sortie
def colorAllShapes():
def colorAllShapes(img):
t = Timer();
img = BMPFile()
# img = BMPFile()
# lecture du fichier
print "| Reading file |",; t.reset();
with open( sys.argv[1] ) as f:
binFile = f.read();
print "%s |" % (t.get())
# # lecture du fichier
# print "| Reading file |",; t.reset();
# with open( sys.argv[1] ) as f:
# binFile = f.read();
# print "%s |" % (t.get())
# parsage
print "| Parsing image |",; t.reset();
img.parse( binFile );
print "%s |" % (t.get())
# # parsage
# print "| Parsing image |",; t.reset();
# img.parse( binFile );
# print "%s |" % (t.get())
@ -988,7 +991,7 @@ def colorAllShapes():
for pixel in line:
# 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
shape = FX.Shape.getShape(pixel, img.content.map)
shape = FX.Shape.getShape(img.drawer, pixel, img.content.map)
print "shape detected"
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
# trace les contours
# Unparse le tout et l'enregistre dans le fichier de sortie
def testStroke():
def testStroke(img):
t = Timer();
img = BMPFile()
# img = BMPFile()
# lecture du fichier
print "| Reading file |",; t.reset();
with open( sys.argv[1] ) as f:
binFile = f.read();
print "%s |" % (t.get())
# print "| Reading file |",; t.reset();
# with open( sys.argv[1] ) as f:
# binFile = f.read();
# print "%s |" % (t.get())
# parsage
print "| Parsing image |",; t.reset();
img.parse( binFile );
print "%s |" % (t.get())
# # parsage
# print "| Parsing image |",; t.reset();
# img.parse( binFile );
# print "%s |" % (t.get())
strokes = []
@ -1058,6 +1061,7 @@ def testStroke():
pixel.setRGB(255,255,255)
else:
pixel.setRGB(0,0,0)
img.drawer.setPixel( pixel );
print "%s |" % (t.get())
@ -1095,28 +1099,28 @@ def testStroke():
# Parse le fichier d'origine
# Applique le filtre
# Unparse l'image et l'enregistre dans le fichier de sortie
def testAverageFilter():
def testAverageFilter(img):
t = Timer();
# lecture du fichier
print "| Reading Image |",; t.reset();
with open( sys.argv[1] ) as file:
binFile = file.read()
print "%s |" % (t.get())
# print "| Reading Image |",; t.reset();
# with open( sys.argv[1] ) as file:
# binFile = file.read()
# print "%s |" % (t.get())
img = BMPFile(); # Instanciation du BMPFile
# img = BMPFile(); # Instanciation du BMPFile
# Parsing
print "| Parsing file |",; t.reset();
img.parse( binFile );
print "%s |" % (t.get())
# # Parsing
# print "| Parsing file |",; t.reset();
# img.parse( binFile );
# print "%s |" % (t.get())
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())
# Unparsing
@ -1150,28 +1154,28 @@ def testAverageFilter():
# Parse le fichier d'origine
# Applique le filtre
# Unparse l'image et l'enregistre dans le fichier de sortie
def testLaplace():
def testLaplace(img):
t = Timer();
# lecture du fichier
print "| Reading Image |",; t.reset();
with open( sys.argv[1] ) as file:
binFile = file.read()
print "%s |" % (t.get())
# # 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
# img = BMPFile(); # Instanciation du BMPFile
# Parsing
print "| Parsing file |",; t.reset();
img.parse( binFile );
print "%s |" % (t.get())
# # Parsing
# print "| Parsing file |",; t.reset();
# img.parse( binFile );
# print "%s |" % (t.get())
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())
# Unparsing
@ -1195,28 +1199,28 @@ def testLaplace():
# Parse le fichier d'origine
# Applique le filtre
# Unparse l'image et l'enregistre dans le fichier de sortie
def testRoberts():
def testRoberts(img):
t = Timer();
# lecture du fichier
print "| Reading Image |",; t.reset();
with open( sys.argv[1] ) as file:
binFile = file.read()
print "%s |" % (t.get())
# print "| Reading Image |",; t.reset();
# with open( sys.argv[1] ) as file:
# binFile = file.read()
# print "%s |" % (t.get())
img = BMPFile(); # Instanciation du BMPFile
# img = BMPFile(); # Instanciation du BMPFile
# Parsing
print "| Parsing file |",; t.reset();
img.parse( binFile );
print "%s |" % (t.get())
# # Parsing
# print "| Parsing file |",; t.reset();
# img.parse( binFile );
# print "%s |" % (t.get())
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())
# Unparsing
@ -1243,28 +1247,28 @@ def testRoberts():
# Parse le fichier d'origine
# Applique le filtre
# Unparse l'image et l'enregistre dans le fichier de sortie
def testPrewitt():
def testPrewitt(img):
t = Timer();
# lecture du fichier
print "| Reading Image |",; t.reset();
with open( sys.argv[1] ) as file:
binFile = file.read()
print "%s |" % (t.get())
# print "| Reading Image |",; t.reset();
# with open( sys.argv[1] ) as file:
# binFile = file.read()
# print "%s |" % (t.get())
img = BMPFile(); # Instanciation du BMPFile
# img = BMPFile(); # Instanciation du BMPFile
# Parsing
print "| Parsing file |",; t.reset();
img.parse( binFile );
print "%s |" % (t.get())
# # Parsing
# print "| Parsing file |",; t.reset();
# img.parse( binFile );
# print "%s |" % (t.get())
print "| Application du filtre |",; t.reset();
FX.Filter.Prewitt(img.content.map);
FX.Filter.Prewitt(img.drawer, img.content.map);
print "%s |" % (t.get())
# Unparsing
@ -1293,28 +1297,28 @@ def testPrewitt():
# Parse le fichier d'origine
# Applique le filtre
# Unparse l'image et l'enregistre dans le fichier de sortie
def testSobel():
def testSobel(img):
t = Timer();
# lecture du fichier
print "| Reading Image |",; t.reset();
with open( sys.argv[1] ) as file:
binFile = file.read()
print "%s |" % (t.get())
# print "| Reading Image |",; t.reset();
# with open( sys.argv[1] ) as file:
# binFile = file.read()
# print "%s |" % (t.get())
img = BMPFile(); # Instanciation du BMPFile
# img = BMPFile(); # Instanciation du BMPFile
# Parsing
print "| Parsing file |",; t.reset();
img.parse( binFile );
print "%s |" % (t.get())
# # Parsing
# print "| Parsing file |",; t.reset();
# img.parse( binFile );
# print "%s |" % (t.get())
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())
# Unparsing
@ -1346,24 +1350,24 @@ def testSobel():
# Parse le fichier d'origine
# Applique le filtre
# Unparse l'image et l'enregistre dans le fichier de sortie
def testConvolution():
def testConvolution(img):
t = Timer();
# lecture du fichier
print "| Reading Image |",; t.reset();
with open( sys.argv[1] ) as file:
binFile = file.read()
print "%s |" % (t.get())
# print "| Reading Image |",; t.reset();
# with open( sys.argv[1] ) as file:
# binFile = file.read()
# print "%s |" % (t.get())
img = BMPFile(); # Instanciation du BMPFile
# img = BMPFile(); # Instanciation du BMPFile
# Parsing
print "| Parsing file |",; t.reset();
img.parse( binFile );
print "%s |" % (t.get())
# # Parsing
# print "| Parsing file |",; t.reset();
# img.parse( binFile );
# print "%s |" % (t.get())
kernel = [
[ 4, 3, 2, 3, 4],
@ -1374,7 +1378,7 @@ def testConvolution():
]
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())
# Unparsing

View File

@ -41,7 +41,7 @@ class Filter:
# 0 -1
#
def Roberts(self, drawer, pixelMap):
return self.Convolution(pixelMap, kernel=[
return self.Convolution(drawer, pixelMap, kernel=[
[1, 0],
[0, -1]
] );
@ -58,7 +58,7 @@ class Filter:
# -1 -1 -1
#
def Laplace(self, drawer, pixelMap):
return self.Convolution(pixelMap, kernel=[
return self.Convolution(drawer, pixelMap, kernel=[
[-1, -1, -1],
[-1, 8, -1],
[-1, -1, -1]
@ -77,7 +77,7 @@ class Filter:
# -1 0 1
#
def Sobel(self, drawer, pixelMap):
return self.Convolution(pixelMap, kernel=[
return self.Convolution(drawer, pixelMap, kernel=[
[-1, 0, 1],
[-2, 0, 2],
[-1, 0, 1]
@ -96,7 +96,7 @@ class Filter:
# -1 0 1
#
def HighPass(self, drawer, pixelMap):
return self.Convolution(pixelMap, kernel=[
return self.Convolution(drawer, pixelMap, kernel=[
[ 0, -1, 0],
[-1, 5, -1],
[ 0, -1, 0]

View File

@ -4,6 +4,11 @@ import random
import time
import sys
sys.path.append(sys.path[0]+'/..')
from BMPFile import RGBPixel
class Shape:
# 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)
#
def getShape(self, originalPixel, pixelMap, seuil=10):
def getShape(self, drawer, originalPixel, pixelMap, seuil=10):
width = len( pixelMap[0] )
height = len( pixelMap )
@ -23,6 +28,16 @@ class Shape:
# on continue d'analyser tant qu'il y a des pixels à traiter
while len(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
shape.append( pixel )
@ -56,7 +71,8 @@ class Shape:
# 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:
# 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 )
@ -142,6 +158,8 @@ class Shape:
# on définit le kernel
k = getKernel(master, position)
pixel = k[position];
# on vide la liste des esclaves
slaves = []