annotate transformations/testtransformations.py @ 104:fe6f96951ed1

corrige nom de la methode get_settings_names_determined_by_complexity(self,complexity)
author SylvainPL <sylvain.pannetier.lebeuf@umontreal.ca>
date Fri, 12 Feb 2010 10:21:21 -0500
parents b3d15100842a
children 291d749452df
rev   line source
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
1 #!/usr/bin/env python
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
2
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
3
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
4 from pylearn.io import filetensor as ft
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
5 import copy
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
6 import pygame
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
7 import time
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
8 import numpy as N
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
9
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
10 #from gimpfu import *
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
11
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
12
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
13 from PoivreSel import PoivreSel
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
14 from thick import Thick
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
15 from BruitGauss import BruitGauss
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
16 from DistorsionGauss import DistorsionGauss
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
17 from PermutPixel import PermutPixel
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
18 from gimp_script import GIMP1
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
19 from Rature import Rature
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
20 from contrast import Contrast
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
21 from local_elastic_distortions import LocalElasticDistorter
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
22 from slant import Slant
80
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
23 from Occlusion import Occlusion
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
24 from add_background_image import AddBackground
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
25 from affine_transform import AffineTransformation
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
26
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
27 ###---------------------order of transformation module
97
b3d15100842a Changed order of transformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 94
diff changeset
28 MODULE_INSTANCES = [Slant(),Thick(),AffineTransformation(),LocalElasticDistorter(),GIMP1(),Rature(),Occlusion(), PermutPixel(),DistorsionGauss(),AddBackground(), PoivreSel(), BruitGauss(), Contrast()]
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
29
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
30 ###---------------------complexity associated to each of them
94
1b8176e9892e cleaning some *.pyc and *.py~ files in pycapcha
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 84
diff changeset
31 complexity = [0.6,0.6,0.6,0.6,0.6,0.3,0.3,0.5,0.5,0.5,0.3,0.3,0.5]
1b8176e9892e cleaning some *.pyc and *.py~ files in pycapcha
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 84
diff changeset
32 complexity = [0.5]*len(MODULE_INSTANCES)
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
33 #complexity = [0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
80
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
34
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
35
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
36
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
37 nbmodule = len(MODULE_INSTANCES)
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
38
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
39 datapath = '/data/lisa/data/nist/by_class/'
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
40 f = open(datapath+'lower/lower_train_data.ft')
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
41 d = ft.read(f)
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
42
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
43 d = d[0:1000,:]/255.0
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
44
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
45 pygame.surfarray.use_arraytype('numpy')
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
46
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
47 #pygame.display.init()
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
48 screen = pygame.Surface((4*(nbmodule+1)/2*32,2*(4*32+20)),depth=32)
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
49
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
50 anglcolorpalette=[(x,x,x) for x in xrange(0,256)]
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
51 #pygame.Surface.set_palette(anglcolorpalette)
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
52 #screen.set_palette(anglcolorpalette)
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
53
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
54 pygame.font.init()
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
55
94
1b8176e9892e cleaning some *.pyc and *.py~ files in pycapcha
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 84
diff changeset
56 for i in range(1000):
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
57 a=d[i,:]
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
58 b=N.asarray(N.reshape(a,(32,32)))
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
59 c=N.asarray([N.reshape(a*255.0,(32,32))]*3).T
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
60 new=pygame.surfarray.make_surface(c)
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
61 new=pygame.transform.scale2x(new)
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
62 new=pygame.transform.scale2x(new)
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
63 #new.set_palette(anglcolorpalette)
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
64 screen.blit(new,(0,0))
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
65
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
66 offset = 4*32
80
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
67 offset2 = 0
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
68 ct = 0
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
69 for j in MODULE_INSTANCES:
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
70 #max dilation
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
71
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
72 #random
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
73 print j.get_settings_names(), j.regenerate_parameters(N.random.rand()*complexity[ct])
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
74
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
75 b=j.transform_image(b)
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
76 c=N.asarray([b*255]*3).T
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
77
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
78 new=pygame.surfarray.make_surface(c)
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
79 new=pygame.transform.scale2x(new)
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
80 new=pygame.transform.scale2x(new)
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
81 #new.set_palette(anglcolorpalette)
80
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
82 screen.blit(new,(offset,offset2))
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
83 font = pygame.font.SysFont('liberationserif',18)
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
84 text = font.render(j.__module__,0,(255,255,255),(0,0,0))
80
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
85 screen.blit(text,(offset,offset2+4*32))
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
86 if ct == len(MODULE_INSTANCES)/2-1:
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
87 offset = 0
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
88 offset2 = 4*32+20
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
89 else:
4407ab3f7805 small display change in testtransformation
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 57
diff changeset
90 offset += 4*32
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
91 ct+=1
94
1b8176e9892e cleaning some *.pyc and *.py~ files in pycapcha
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 84
diff changeset
92 pygame.image.save(screen,'/u/glorotxa/exemples/%s.PNG'%i)
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
93 #raw_input('Press Enter')
57
6846136b2201 Add a simple test script to see transformation step by step
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
94
84
104e0b8a1c70 testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 80
diff changeset
95 #pygame.display.quit()