# HG changeset patch # User Xavier Glorot # Date 1265603345 18000 # Node ID 6846136b2201349e45b5e7eed8d2375d552ad203 # Parent d9d836d3c6256c0ff4fbf07d330590148557dede Add a simple test script to see transformation step by step diff -r d9d836d3c625 -r 6846136b2201 transformations/testtransformations.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/transformations/testtransformations.py Sun Feb 07 23:29:05 2010 -0500 @@ -0,0 +1,85 @@ +#!/usr/bin/env python + + +from pylearn.io import filetensor as ft +import copy +import pygame +import time +import numpy as N + +#from gimpfu import * + + +from PoivreSel import PoivreSel +from thick import Thick +from BruitGauss import BruitGauss +from DistorsionGauss import DistorsionGauss +from PermutPixel import PermutPixel +#from gimp_script import GIMPTransformation +from Rature import Rature +from contrast import Contrast +from local_elastic_distortions import LocalElasticDistorter +from slant import Slant +#from Occlusion import Occlusion +from add_background_image import AddBackground +from affine_transform import AffineTransformation + +###---------------------order of transformation module +MODULE_INSTANCES = [Thick(),Slant(),AffineTransformation(), LocalElasticDistorter(), PermutPixel(), Rature(), BruitGauss(),PoivreSel(), Contrast()] + +###---------------------complexity associated to each of them +complexity = [0.6,0.7,0.5,0.4,0.1,0.5,0.03,0.03,0.5] + + +nbmodule = len(MODULE_INSTANCES) + +datapath = '/data/lisa/data/nist/by_class/' +f = open(datapath+'lower/lower_train_data.ft') +d = ft.read(f) + +d = d[0:1000,:]/255.0 + +pygame.surfarray.use_arraytype('numpy') + +pygame.display.init() +screen = pygame.display.set_mode((4*(nbmodule+1)*32,4*32+20),0,8) +anglcolorpalette=[(x,x,x) for x in xrange(0,256)] +screen.set_palette(anglcolorpalette) + +pygame.font.init() + +for i in range(10000): + a=d[i,:] + b=N.asarray(N.reshape(a,(32,32))) + c=N.asarray(N.reshape(a*255.0,(32,32))).T + new=pygame.surfarray.make_surface(c) + new=pygame.transform.scale2x(new) + new=pygame.transform.scale2x(new) + new.set_palette(anglcolorpalette) + screen.blit(new,(0,0)) + + offset = 4*32 + ct = 0 + for j in MODULE_INSTANCES: + #max dilation + + #random + print j.get_settings_names(), j.regenerate_parameters(complexity[ct]) + + b=j.transform_image(b) + c=N.asarray(b*255).T + + new=pygame.surfarray.make_surface(c) + new=pygame.transform.scale2x(new) + new=pygame.transform.scale2x(new) + new.set_palette(anglcolorpalette) + screen.blit(new,(offset,0)) + font = pygame.font.SysFont('liberationserif',18) + text = font.render(j.__module__,0,(255,255,255),(0,0,0)) + screen.blit(text,(offset,4*32)) + offset += 4*32 + ct+=1 + pygame.display.update() + raw_input('Press Enter') + +pygame.display.quit()