comparison transformations/testtransformations.py @ 57:6846136b2201

Add a simple test script to see transformation step by step
author Xavier Glorot <glorotxa@iro.umontreal.ca>
date Sun, 07 Feb 2010 23:29:05 -0500
parents
children 4407ab3f7805
comparison
equal deleted inserted replaced
56:d9d836d3c625 57:6846136b2201
1 #!/usr/bin/env python
2
3
4 from pylearn.io import filetensor as ft
5 import copy
6 import pygame
7 import time
8 import numpy as N
9
10 #from gimpfu import *
11
12
13 from PoivreSel import PoivreSel
14 from thick import Thick
15 from BruitGauss import BruitGauss
16 from DistorsionGauss import DistorsionGauss
17 from PermutPixel import PermutPixel
18 #from gimp_script import GIMPTransformation
19 from Rature import Rature
20 from contrast import Contrast
21 from local_elastic_distortions import LocalElasticDistorter
22 from slant import Slant
23 #from Occlusion import Occlusion
24 from add_background_image import AddBackground
25 from affine_transform import AffineTransformation
26
27 ###---------------------order of transformation module
28 MODULE_INSTANCES = [Thick(),Slant(),AffineTransformation(), LocalElasticDistorter(), PermutPixel(), Rature(), BruitGauss(),PoivreSel(), Contrast()]
29
30 ###---------------------complexity associated to each of them
31 complexity = [0.6,0.7,0.5,0.4,0.1,0.5,0.03,0.03,0.5]
32
33
34 nbmodule = len(MODULE_INSTANCES)
35
36 datapath = '/data/lisa/data/nist/by_class/'
37 f = open(datapath+'lower/lower_train_data.ft')
38 d = ft.read(f)
39
40 d = d[0:1000,:]/255.0
41
42 pygame.surfarray.use_arraytype('numpy')
43
44 pygame.display.init()
45 screen = pygame.display.set_mode((4*(nbmodule+1)*32,4*32+20),0,8)
46 anglcolorpalette=[(x,x,x) for x in xrange(0,256)]
47 screen.set_palette(anglcolorpalette)
48
49 pygame.font.init()
50
51 for i in range(10000):
52 a=d[i,:]
53 b=N.asarray(N.reshape(a,(32,32)))
54 c=N.asarray(N.reshape(a*255.0,(32,32))).T
55 new=pygame.surfarray.make_surface(c)
56 new=pygame.transform.scale2x(new)
57 new=pygame.transform.scale2x(new)
58 new.set_palette(anglcolorpalette)
59 screen.blit(new,(0,0))
60
61 offset = 4*32
62 ct = 0
63 for j in MODULE_INSTANCES:
64 #max dilation
65
66 #random
67 print j.get_settings_names(), j.regenerate_parameters(complexity[ct])
68
69 b=j.transform_image(b)
70 c=N.asarray(b*255).T
71
72 new=pygame.surfarray.make_surface(c)
73 new=pygame.transform.scale2x(new)
74 new=pygame.transform.scale2x(new)
75 new.set_palette(anglcolorpalette)
76 screen.blit(new,(offset,0))
77 font = pygame.font.SysFont('liberationserif',18)
78 text = font.render(j.__module__,0,(255,255,255),(0,0,0))
79 screen.blit(text,(offset,4*32))
80 offset += 4*32
81 ct+=1
82 pygame.display.update()
83 raw_input('Press Enter')
84
85 pygame.display.quit()