denoising.py/docs/Noise.readme

210 lines
5.1 KiB
Plaintext
Raw Permalink Normal View History

2015-09-18 08:51:49 +00:00
Classes:
/******************/
/** COLORIZATION **/
/******************/
Principe: colorer en modifiant les pixels (n&b) dans un ton (teinte) précisée
restitue la contraste mais recentre la couleur autour de la teinte
/************ ALGO **************/
i = 50 // incertitude
t = RGBPixel(1,2,3) // teinte souhaitée
p = RGBPixel(1,2,3) // couleur actuelle
/************ CODE **************/
def colorize(pixel, tint):
/*****************/
/** SHAPIZATION **/
/*****************/
Principe: récupérer une forme par récurrence
Ajouter les 8 bits périphériques du pixel courant s'il existe et s'il a des couleurs pas trop éloignées des précédentes
/************ ALGO **************/
/************ CODE **************/
def getShape(self, coords, pixelMap, pixelList ): # return PixelList
# coords = [lastx, lasty, x, y]
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 pixelMap)
if x<width and x>=0 and y<height and y>=0:
already = False;
for i in range(0, len(pixelList)):
if pixelList[i] == pixelMap[y][x]:
already = True;
break
# si le pixel n'est pas déjà dans le tableau
if not already:
pixelMap[y][x].setRGB(255,0,0); # debug, tout rouge
pixelList.append( pixelMap[y][x] ) # ajout au tableau
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
self.getShape(newCoords+[x+1, y], pixelMap, pixelList) # 6
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
def getShapeRecursive(self, coords, pixelMap, pixelList ): # return PixelList
# coords = [lastx, lasty, x, y]
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 pixelMap)
if x<width and x>=0 and y<height and y>=0:
already = False;
for i in range(0, len(pixelList)):
if pixelList[i] == pixelMap[y][x]:
already = True;
break
# si le pixel n'est pas déjà dans le tableau
if not already:
pixelMap[y][x].setRGB(255,0,0);
# si trop de différence
lastP = pixelMap[lasty][lastx]
pix = pixelMap[y][x]
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.getShapeRecursive( [x, y, x-1, y+1], pixelMap, pixelList) # 1
self.getShapeRecursive( [x, y, x, y+1], pixelMap, pixelList) # 2
self.getShapeRecursive( [x, y, x+1, y+1], pixelMap, pixelList) # 3
self.getShapeRecursive( [x, y, x-1, y ], pixelMap, pixelList) # 4
# current pixel
self.getShapeRecursive( [x, y, x+1, y ], pixelMap, pixelList) # 6
self.getShapeRecursive( [x, y, x-1, y-1], pixelMap, pixelList) # 7
self.getShapeRecursive( [x, y, x, y-1], pixelMap, pixelList) # 8
self.getShapeRecursive( [x, y, x+1, y-1], pixelMap, pixelList) # 9
# identique à la version récursive mais sans récursivité (+ réécriture)
### ALGO ###
HA.
On reconnaît une forme distincte par l'écart de teinte/contraste avec les alentours
A l'échelle du pixel, 2 méthodes de distinction de forme:
1- On détecte les contours
recherche d'un contour (écart)
suivi du contour
transposition en forme
2- détection de la forme
élargissement de zone jusqu'à un contour (écart)
Alternative de niveau 1:
* balayage des abscisses puis racollage
### CODE ###
def getShape(self, coords, pixelMap, pixelList):
# coords = [lastx, lasty, x, y]
width = len( pixelMap[0] )
height = len( pixelMap )
2015-09-18 08:51:49 +00:00
lastx = coords[0]
lasty = coords[1]
x = coords[2]
y = coords[3]
2015-09-18 08:51:49 +00:00
if x<width and x>=0 and y<height and y>=0:
2015-09-18 08:51:49 +00:00
already = False;
for pix in pixelList:
if pix == pixelMap[y][x]:
already = True;
break
2015-09-18 08:51:49 +00:00
# si le pixel n'est pas déjà dans le tableau
if not already:
2015-09-18 08:51:49 +00:00
# si trop de différence
lastP = pixelMap[lasty][lastx]
pix = pixelMap[y][x]
2015-09-18 08:51:49 +00:00
if abs(lastP.r-pix.r) <= 50 and abs(lastP.g-pix.g) <= 50 and abs(lastP.b-pix.b) <= 50:
2015-09-18 08:51:49 +00:00
return pixelMap[y][x];
2015-09-18 08:51:49 +00:00
# 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
2015-09-18 08:51:49 +00:00
# self.getShape( [x, y, x-1, y ], pixelMap, pixelList) # 4
# # current pixel
# self.getShape( [x, y, x+1, y ], pixelMap, pixelList) # 6
2015-09-18 08:51:49 +00:00
# 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
2015-09-18 08:51:49 +00:00
return None # return none si le pixel n'est plus de la forme