Mercurial > ift6266
view transformations/PermutPixel.py @ 78:9936c4886299
Mise a niveau specifications parametres deterministes, bruitage moins aggressif et transformations toutes pareilles tant qu'on ne rappelle pas regenerate_parameters()
author | SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca> |
---|---|
date | Wed, 10 Feb 2010 14:51:18 -0500 |
parents | 48a21d19b8eb |
children | 6696391273ab |
line wrap: on
line source
#!/usr/bin/python # coding: utf-8 ''' Un echange de pixels est effectue entre certain pixels choisit aleatoirement et un de ses 4 voisins, tout aussi choisi aleatoirement. Le nombre de pixels permutes est definit pas complexity*1024 Sylvain Pannetier Lebeuf dans le cadre de IFT6266, hiver 2010 ''' import numpy import random class PermutPixel(): def __init__(self): self.nombre=10 #Le nombre de pixels a permuter self.proportion=0.3 def get_settings_names(self): return [] def get_settings_name_determined_by_complexity(self): return ['nombre'] def regenerate_parameters(self, complexity): self.proportion=float(complexity)/3 self.nombre=int(256*self.proportion)*4 #Par multiple de 4 (256=1024/4) self.echantillon=random.sample(xrange(0,1024),self.nombre) #Les pixels qui seront permutes return self._get_current_parameters() def _get_current_parameters(self): return [] def get_parameters_determined_by_complexity(self, complexity): return [int(complexity*256)*4] def transform_image(self, image): image=image.reshape(1024,1) temp=0 #variable temporaire for i in xrange(0,self.nombre,4): #Par bonds de 4 #gauche if self.echantillon[i] > 0: temp=image[self.echantillon[i]-1] image[self.echantillon[i]-1]=image[self.echantillon[i]] image[self.echantillon[i]]=temp #droite if self.echantillon[i+1] < 1023: temp=image[self.echantillon[i+1]+1] image[self.echantillon[i+1]+1]=image[self.echantillon[i+1]] image[self.echantillon[i+1]]=temp #haut if self.echantillon[i+2] > 31: temp=image[self.echantillon[i+2]-32] image[self.echantillon[i+2]-32]=image[self.echantillon[i+2]] image[self.echantillon[i+2]]=temp #bas if self.echantillon[i+3] < 992: temp=image[self.echantillon[i+3]+32] image[self.echantillon[i+3]+32]=image[self.echantillon[i+3]] image[self.echantillon[i+3]]=temp return image.reshape((32,32)) #---TESTS--- def _load_image(): f = open('/home/sylvain/Dropbox/Msc/IFT6266/donnees/lower_test_data.ft') #Le jeu de donnees est en local. d = ft.read(f) w=numpy.asarray(d[random.randint(0,100)]) return (w/255.0).astype('float') def _test(complexite): img=_load_image() transfo = PermutPixel() pylab.imshow(img.reshape((32,32))) pylab.show() print transfo.get_settings_names() print transfo.regenerate_parameters(complexite) img_trans=transfo.transform_image(img) pylab.imshow(img_trans.reshape((32,32))) pylab.show() if __name__ == '__main__': from pylearn.io import filetensor as ft import pylab for i in xrange(0,5): _test(0)