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-08 20:42:28 +00:00
|
|
|
import random
|
2015-09-06 12:54:58 +00:00
|
|
|
import sys
|
|
|
|
|
2015-09-08 19:17:00 +00:00
|
|
|
|
2015-09-09 20:12:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-09-08 20:42:28 +00:00
|
|
|
def testFileIntegrity():
|
|
|
|
# lecture du fichier
|
|
|
|
with open( sys.argv[1] ) as file:
|
|
|
|
binFile = file.read()
|
|
|
|
|
|
|
|
# Instanciation du BMPFile
|
|
|
|
img = BMPFile()
|
|
|
|
|
|
|
|
# Parsing
|
|
|
|
img.parse( binFile );
|
|
|
|
|
2015-09-11 07:25:44 +00:00
|
|
|
# détection des formes
|
|
|
|
noise = Noise();
|
|
|
|
|
|
|
|
pixelsDone = []
|
|
|
|
for y in range(0,len(img.content.map)):
|
|
|
|
for x in range(0, len(img.content.map[0])):
|
|
|
|
# on traite si on a pas déjà
|
|
|
|
already = False
|
|
|
|
for i in pixelsDone:
|
|
|
|
if i == img.content.map[y][x]:
|
|
|
|
already = True
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
if not already:
|
|
|
|
pixelList = []
|
|
|
|
|
|
|
|
randomRGB = [random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)]
|
|
|
|
|
|
|
|
noise.getShape([x, y, x, y], img.content.map, pixelList)
|
|
|
|
|
|
|
|
for pixel in pixelList:
|
|
|
|
pixel.setRGB(randomRGB[0], randomRGB[1], randomRGB[2]);
|
|
|
|
|
|
|
|
pixelsDone = pixelsDone + pixelList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#inct = 50; # incertitude
|
2015-09-10 19:24:26 +00:00
|
|
|
|
2015-09-09 20:37:44 +00:00
|
|
|
# MODIFICATIONS des pixels
|
2015-09-11 07:25:44 +00:00
|
|
|
#for line in img.content.map:
|
|
|
|
# for pixel in line:
|
|
|
|
# pixel.setRGB(
|
|
|
|
# (230-25) + (2*25*pixel.r/256), # 230 ± 25
|
|
|
|
# (170-inct) + (2*inct*pixel.g/256), # 170 ± 50
|
|
|
|
# (100-inct) + (2*inct*pixel.b/256), # 100 ± 50
|
|
|
|
# bpp=24
|
|
|
|
# )
|
2015-09-08 20:42:28 +00:00
|
|
|
|
|
|
|
|
2015-09-09 20:37:44 +00:00
|
|
|
# Unparsing
|
|
|
|
img.unparse()
|
2015-09-08 20:42:28 +00:00
|
|
|
|
|
|
|
|
2015-09-09 20:37:44 +00:00
|
|
|
print img.binData
|
2015-09-08 19:17:00 +00:00
|
|
|
|
2015-09-06 12:54:58 +00:00
|
|
|
|
2015-09-07 08:11:04 +00:00
|
|
|
|
2015-09-06 21:34:26 +00:00
|
|
|
|
|
|
|
|
2015-09-08 20:42:28 +00:00
|
|
|
def testManualCreation():
|
|
|
|
img = BMPFile()
|
|
|
|
for y in range(0, 100):
|
|
|
|
img.content.map.append( [] )
|
2015-09-09 20:12:37 +00:00
|
|
|
for x in range(0, 100):
|
2015-09-09 16:18:21 +00:00
|
|
|
img.content.map[y].append( RGBPixel(
|
2015-09-08 20:42:28 +00:00
|
|
|
random.randint(0, 255),
|
|
|
|
random.randint(0, 255),
|
2015-09-09 20:12:37 +00:00
|
|
|
random.randint(0, 255),
|
|
|
|
bpp=24
|
2015-09-08 20:42:28 +00:00
|
|
|
) );
|
2015-09-06 21:34:26 +00:00
|
|
|
|
2015-09-08 20:42:28 +00:00
|
|
|
img.unparse();
|
2015-09-07 17:21:32 +00:00
|
|
|
|
2015-09-08 20:42:28 +00:00
|
|
|
print img.binData
|
2015-09-07 08:24:28 +00:00
|
|
|
|
2015-09-08 20:42:28 +00:00
|
|
|
# MAIN
|
2015-09-09 20:12:37 +00:00
|
|
|
#testManualCreation()
|
|
|
|
testFileIntegrity()
|