2015-09-06 12:54:58 +00:00
# ~*~ encoding: utf-8 ~*~ #
###########################
# TRAITEMENT D'IMAGES #
###########################
2015-09-06 14:01:17 +00:00
# classes
2015-09-09 13:52:20 +00:00
from BMPFile import *
2015-09-10 21:37:17 +00:00
from Noise import *
2015-09-17 19:15:42 +00:00
from tests import *
2015-09-08 20:42:28 +00:00
import random
2015-09-06 12:54:58 +00:00
import sys
2015-09-14 19:58:21 +00:00
import time
2015-09-08 19:17:00 +00:00
2015-09-17 22:33:14 +00:00
# arrêt si moins de 2 arguments
if len ( sys . argv ) < 3 :
print " Require 2 args : \n * input image \n * output image "
exit ( )
2015-09-17 13:55:16 +00:00
2015-09-17 22:33:14 +00:00
################" INTERFACE "###################
2015-09-18 11:55:22 +00:00
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 " , 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 ( " Difference par P " , 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 " +---------------------------+ "
2015-09-19 19:26:45 +00:00
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 )
2015-09-21 11:55:31 +00:00
print " | 32) %s | " % exactLength ( " Colorer les formes " , 21 , - 1 )
2015-09-24 17:52:49 +00:00
print " | 33) %s | " % exactLength ( " Relever les contours " , 21 , - 1 )
2015-09-19 19:26:45 +00:00
print " +---------------------------+ "
2015-09-20 15:37:54 +00:00
print " | %s | " % exactLength ( " TESTS DE FILTRES " , 25 , 0 )
print " | %s | " % exactLength ( " " , 25 , 0 )
print " | 40) %s | " % exactLength ( " Lissage " , 21 , - 1 )
2015-09-21 11:55:31 +00:00
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 )
2015-09-20 15:37:54 +00:00
print " +---------------------------+ "
2015-09-17 22:33:14 +00:00
print
while True :
action = int ( raw_input ( " choix: " ) )
2015-09-20 15:37:54 +00:00
if action > = 0 and action < 50 :
2015-09-17 22:33:14 +00:00
break ;
2015-09-19 19:26:45 +00:00
startStr = " \n +---------------------------+---------+ "
result = " "
2015-09-17 22:33:14 +00:00
execTime = Timer ( ) ; execTime . reset ( ) ;
2015-09-18 08:45:46 +00:00
2015-09-18 11:55:22 +00:00
# fichier
2015-09-17 22:33:14 +00:00
if action == 0 :
2015-09-19 19:26:45 +00:00
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
2015-09-17 22:33:14 +00:00
elif action == 1 :
2015-09-19 19:26:45 +00:00
print startStr
2015-09-18 08:45:46 +00:00
result = testFileIntegrity ( ) # teste le PARSE/UNPARSE
2015-09-17 22:33:14 +00:00
elif action == 2 :
2015-09-19 19:26:45 +00:00
print startStr
2015-09-18 08:45:46 +00:00
result = printIntPalette ( ) # affiche la palette d'une image
2015-09-18 11:55:22 +00:00
# bruits
elif action == 10 :
2015-09-19 19:26:45 +00:00
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 ( arg1 , arg2 , arg3 , arg4 ) # teste le bruitage/débruitage de type "Sel & Poivre"
2015-09-18 11:55:22 +00:00
elif action == 11 :
2015-09-19 19:26:45 +00:00
print startStr
2015-09-18 11:55:22 +00:00
testAdditiveNoise ( ) # teste le bruitage/débruitage de type "Additif"
# performances
elif action == 20 :
2015-09-19 19:26:45 +00:00
print startStr
2015-09-18 11:55:22 +00:00
printImageQuality ( ) # compare 2 images et donne le pourcentage de ressemblance/différence
elif action == 21 :
2015-09-19 19:26:45 +00:00
print startStr
2015-09-18 09:58:01 +00:00
print " not implemented yet "
exit ( )
2015-09-18 11:55:22 +00:00
printImageQualityByPower ( ) # compare 2 images et donne le pourcentage de ressemblance/différence (utilisant la puissance)
elif action == 22 :
2015-09-19 19:26:45 +00:00
print startStr
2015-09-18 11:55:22 +00:00
imageForImageQuality ( ) # crée une image correspondant aux différences de 2 images
elif action == 23 :
2015-09-19 19:26:45 +00:00
print startStr
2015-09-18 11:55:22 +00:00
mergeImagesAdditive ( ) # crée une image étant la fusion (addition) de 2 images
elif action == 24 :
2015-09-19 19:26:45 +00:00
print startStr
2015-09-18 11:55:22 +00:00
mergeImagesSubstractive ( ) # crée une image étant la fusion (soustractive) de 2 images
2015-09-19 19:26:45 +00:00
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 ( 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 ( arg1 , arg2 ) # colorie la forme contenant le pixel de coordonnées donné
2015-09-21 11:55:31 +00:00
elif action == 32 :
print startStr
colorAllShapes ( ) # colorie la forme contenant le pixel de coordonnées donné
2015-09-24 17:52:49 +00:00
elif action == 33 :
print startStr
testStroke ( ) # trace les contours uniquement à partir de formes pleines
2015-09-20 15:37:54 +00:00
# filtres
elif action == 40 :
s = raw_input ( " Seuil [5]: " ) ;
arg1 = 5
if s != " " :
arg1 = int ( s )
print startStr
2015-09-21 11:55:31 +00:00
testSmooth ( arg1 ) # teste le lissage
2015-09-20 15:37:54 +00:00
elif action == 41 :
print startStr
2015-09-21 11:55:31 +00:00
testLaplace ( ) # teste le filtre de Laplace
2015-09-20 15:37:54 +00:00
elif action == 42 :
print startStr
2015-09-21 11:55:31 +00:00
testRoberts ( ) # teste le filtre de Roberts
2015-09-20 15:37:54 +00:00
elif action == 43 :
print startStr
2015-09-21 11:55:31 +00:00
testPrewitt ( ) # teste le filtre de Prewitt
elif action == 44 :
print startStr
testSobel ( ) # teste le filtre de Sobel
elif action == 45 :
print startStr
testConvolution ( ) # teste le filtre de Convolution
elif action == 46 :
print startStr
testBichrome ( ) # teste le passage au bichromatique
2015-09-20 15:37:54 +00:00
2015-09-17 22:33:14 +00:00
else :
2015-09-18 11:55:22 +00:00
print " Wrong choice "
exit ( ) ;
2015-09-17 22:33:14 +00:00
2015-09-18 11:55:22 +00:00
print " +---------------------------+---------+ "
print " | EXECUTION TIME | %s | " % execTime . get ( )
print " +---------------------------+---------+ "
2015-09-18 08:45:46 +00:00
print
print result
2015-09-17 13:55:16 +00:00
2015-09-16 19:14:08 +00:00
############ TESTS ############
2015-09-17 19:15:42 +00:00
# testManualCreation() # teste la création d'un fichier à partir d'une matrice uniquement
# testFileIntegrity() # teste le PARSE/UNPARSE
# printIntPalette() # affiche la palette d'une image
2015-09-16 19:14:08 +00:00
2015-09-17 19:15:42 +00:00
# testSaltAndPepper() # teste le bruitage/débruitage de type "Sel & Poivre"
# testAdditiveNoise() # teste le bruitage/débruitage de type "Additif"
2015-09-16 19:14:08 +00:00
2015-09-17 22:33:14 +00:00
# printImageQuality() # compare 2 images et donne le pourcentage de ressemblance/différence
2015-09-16 19:14:08 +00:00
2015-09-17 19:15:42 +00:00
# imageForImageQuality() # crée une image correspondant aux différences de 2 images
# mergeImages() # crée une image étant la fusion (addition) de 2 images
2015-09-16 19:14:08 +00:00
############ CALIBRATE ############
2015-09-17 19:15:42 +00:00
# calSaltAndPepper() # Calibration en créant des fichiers pour les paramètres différents de débruitage dans le dossier /SaltAndPepper (sert à comparer)