Detection forme

This commit is contained in:
xdrm-brackets 2015-09-11 09:25:44 +02:00
parent aa7d1eee34
commit c14eecfdee
5 changed files with 95 additions and 42 deletions

View File

@ -2,34 +2,50 @@
class Noise: class Noise:
def getShape( x, y, map, pixelList ): # return PixelList def getShape(self, coords, pixelMap, pixelList ): # return PixelList
width = len( map[0] ) # coords = [lastx, lasty, x, y]
height = len( map ) width = len( pixelMap[0] )
height = len( pixelMap )
lastx = coords[0]
lasty = coords[1]
x = coords[2]
y = coords[3]
newCoords = [x, y]
# si le pixel existe (pas de dépassement de la map) # si le pixel existe (pas de dépassement de la pixelMap)
if x < width and y < height: if x<width and x>=0 and y<height and y>=0:
already = False; already = False;
for i in range(0, len(pixelList)): for i in range(0, len(pixelList)):
if pixelList[i] == map[y][x]: if pixelList[i] == pixelMap[y][x]:
already = True; already = True;
break break
# si le pixel n'est pas déjà dans le tableau # si le pixel n'est pas déjà dans le tableau
if not already: if not already:
pixelList.append( map[y][x] ) # ajout au tableau
getShape(x-1, y+1, map, pixelList) # 1 # si trop de différence
getShape(x, y+1, map, pixelList) # 2 lastP = pixelMap[lasty][lastx]
getShape(x+1, y+1, map, pixelList) # 3 pix = pixelMap[y][x]
getShape(x-1, y, map, pixelList) # 4
# current pixel
getShape(x+1, y, map, pixelList) # 6
getShape(x-1, y-1, map, pixelList) # 7
getShape(x, y-1, map, pixelList) # 8 if abs(lastP.r-pix.r) <= 50 and abs(lastP.g-pix.g) <= 50 and abs(lastP.b-pix.b) <= 50:
getShape(x+1, y-1, map, pixelList) # 9
pixelList.append( pixelMap[y][x] ) # ajout au tableau
self.getShape( [x, y, x-1, y+1], pixelMap, pixelList) # 1
self.getShape( [x, y, x, y+1], pixelMap, pixelList) # 2
self.getShape( [x, y, x+1, y+1], pixelMap, pixelList) # 3
self.getShape( [x, y, x-1, y ], pixelMap, pixelList) # 4
# current pixel
self.getShape( [x, y, x+1, y ], pixelMap, pixelList) # 6
self.getShape( [x, y, x-1, y-1], pixelMap, pixelList) # 7
self.getShape( [x, y, x, y-1], pixelMap, pixelList) # 8
self.getShape( [x, y, x+1, y-1], pixelMap, pixelList) # 9

View File

@ -27,34 +27,43 @@ Ajouter les 8 bits périphériques du pixel courant s'il existe et s'il a des co
/************ ALGO **************/ /************ ALGO **************/
/************ CODE **************/ /************ CODE **************/
def getShape( x, y, map, pixelList): # return PixelList def getShape(self, coords, pixelMap, pixelList ): # return PixelList
width = len( map[0] ) # coords = [lastx, lasty, x, y]
height = len( map ) width = len( pixelMap[0] )
height = len( pixelMap )
lastx = coords[0]
lasty = coords[1]
x = coords[2]
y = coords[3]
newCoords = [x, y]
# si le pixel existe (pas de dépassement de la map) # si le pixel existe (pas de dépassement de la pixelMap)
if x < width and y < height: if x<width and x>=0 and y<height and y>=0:
already = False; already = False;
for i in range(0, len(pixelList)): for i in range(0, len(pixelList)):
if pixelList[i] == map[y][x]: if pixelList[i] == pixelMap[y][x]:
already = True; already = True;
break break
# si le pixel n'est pas déjà dans le tableau # si le pixel n'est pas déjà dans le tableau
if not already: if not already:
pixelList.append( map[y][x] ) # ajout au tableau pixelMap[y][x].setRGB(255,0,0); # debug, tout rouge
getShape(x-1, y+1, map, pixelList) # 1 pixelList.append( pixelMap[y][x] ) # ajout au tableau
getShape(x, y+1, map, pixelList) # 2
getShape(x+1, y+1, map, pixelList) # 3
getShape(x-1, y, map, pixelList) # 4 self.getShape(newCoords+[x-1, y+1], pixelMap, pixelList) # 1
self.getShape(newCoords+[x, y+1], pixelMap, pixelList) # 2
self.getShape(newCoords+[x+1, y+1], pixelMap, pixelList) # 3
self.getShape(newCoords+[x-1, y], pixelMap, pixelList) # 4
# current pixel # current pixel
getShape(x+1, y, map, pixelList) # 6 self.getShape(newCoords+[x+1, y], pixelMap, pixelList) # 6
getShape(x-1, y-1, map, pixelList) # 7 self.getShape(newCoords+[x-1, y-1], pixelMap, pixelList) # 7
getShape(x, y-1, map, pixelList) # 8 self.getShape(newCoords+[x, y-1], pixelMap, pixelList) # 8
getShape(x+1, y-1, map, pixelList) # 9 self.getShape(newCoords+[x+1, y-1], pixelMap, pixelList) # 9

View File

@ -30,17 +30,45 @@ def testFileIntegrity():
# Parsing # Parsing
img.parse( binFile ); img.parse( binFile );
inct = 50; # incertitude # 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
# MODIFICATIONS des pixels # MODIFICATIONS des pixels
for line in img.content.map: #for line in img.content.map:
for pixel in line: # for pixel in line:
pixel.setRGB( # pixel.setRGB(
(230-25) + (2*25*pixel.r/256), # 230 ± 25 # (230-25) + (2*25*pixel.r/256), # 230 ± 25
(170-inct) + (2*inct*pixel.g/256), # 170 ± 50 # (170-inct) + (2*inct*pixel.g/256), # 170 ± 50
(100-inct) + (2*inct*pixel.b/256), # 100 ± 50 # (100-inct) + (2*inct*pixel.b/256), # 100 ± 50
bpp=24 # bpp=24
) # )
# Unparsing # Unparsing

Binary file not shown.

After

Width:  |  Height:  |  Size: 442 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 768 KiB

After

Width:  |  Height:  |  Size: 443 B