Detection forme
This commit is contained in:
parent
aa7d1eee34
commit
c14eecfdee
|
@ -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
|
# si trop de différence
|
||||||
|
lastP = pixelMap[lasty][lastx]
|
||||||
|
pix = pixelMap[y][x]
|
||||||
|
|
||||||
getShape(x-1, y+1, map, pixelList) # 1
|
|
||||||
getShape(x, y+1, map, pixelList) # 2
|
|
||||||
getShape(x+1, y+1, map, pixelList) # 3
|
|
||||||
|
|
||||||
getShape(x-1, y, map, pixelList) # 4
|
|
||||||
|
if abs(lastP.r-pix.r) <= 50 and abs(lastP.g-pix.g) <= 50 and abs(lastP.b-pix.b) <= 50:
|
||||||
|
|
||||||
|
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
|
# current pixel
|
||||||
getShape(x+1, y, map, pixelList) # 6
|
self.getShape( [x, y, x+1, y ], pixelMap, pixelList) # 6
|
||||||
|
|
||||||
getShape(x-1, y-1, map, pixelList) # 7
|
self.getShape( [x, y, x-1, y-1], pixelMap, pixelList) # 7
|
||||||
getShape(x, y-1, map, pixelList) # 8
|
self.getShape( [x, y, x, y-1], pixelMap, pixelList) # 8
|
||||||
getShape(x+1, y-1, map, pixelList) # 9
|
self.getShape( [x, y, x+1, y-1], pixelMap, pixelList) # 9
|
||||||
|
|
|
@ -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
|
|
||||||
getShape(x, y-1, map, pixelList) # 8
|
|
||||||
getShape(x+1, y-1, map, pixelList) # 9
|
|
||||||
|
|
||||||
|
self.getShape(newCoords+[x-1, y-1], pixelMap, pixelList) # 7
|
||||||
|
self.getShape(newCoords+[x, y-1], pixelMap, pixelList) # 8
|
||||||
|
self.getShape(newCoords+[x+1, y-1], pixelMap, pixelList) # 9
|
46
code/bmp.py
46
code/bmp.py
|
@ -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 |
BIN
code/new.bmp
BIN
code/new.bmp
Binary file not shown.
Before Width: | Height: | Size: 768 KiB After Width: | Height: | Size: 443 B |
Loading…
Reference in New Issue