Mercurial > ift6266
view transformations/DistorsionGauss.py @ 65:ab70fbca513c
Change path to AddBackground and add a image_file attribute (not to do a listdir at each image)
author | Xavier Glorot <glorotxa@iro.umontreal.ca> |
---|---|
date | Tue, 09 Feb 2010 18:31:24 -0500 |
parents | 3bc75139654a |
children | aee278ebc827 |
line wrap: on
line source
#!/usr/bin/python # coding: utf-8 ''' Ajout d'une composante aleatoire dans chaque pixel de l'image. C'est une distorsion gaussienne de moyenne 0 et d'écart type complexity/10 Sylvain Pannetier Lebeuf dans le cadre de IFT6266, hiver 2010 ''' import numpy import random class DistorsionGauss(): def __init__(self): self.ecart_type=0.1 #L'ecart type de la gaussienne def get_settings_names(self): return ['ecart_type'] def regenerate_parameters(self, complexity): self.ecart_type=float(complexity)/10 return self._get_current_parameters() def _get_current_parameters(self): return [] def get_parameters_determined_by_complexity(self, complexity): return [float(complexity)/10] def transform_image(self, image): image=image.reshape(1024,1) aleatoire=numpy.zeros((1024,1)).astype('float32') for i in xrange(0,1024): aleatoire[i]=float(random.gauss(0,self.ecart_type)) image=image+aleatoire #Ramener tout entre 0 et 1 if numpy.min(image) < 0: image-=numpy.min(image) if numpy.max(image) > 1: image/=numpy.max(image) 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 = DistorsionGauss() 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(1)