comparison transformations/testtransformations.py @ 84:104e0b8a1c70

testtransformation now work with all the transformations and save image files (.PNG) to a hard coded path
author Xavier Glorot <glorotxa@iro.umontreal.ca>
date Wed, 10 Feb 2010 17:38:17 -0500
parents 4407ab3f7805
children 1b8176e9892e
comparison
equal deleted inserted replaced
83:f75f5acad4eb 84:104e0b8a1c70
13 from PoivreSel import PoivreSel 13 from PoivreSel import PoivreSel
14 from thick import Thick 14 from thick import Thick
15 from BruitGauss import BruitGauss 15 from BruitGauss import BruitGauss
16 from DistorsionGauss import DistorsionGauss 16 from DistorsionGauss import DistorsionGauss
17 from PermutPixel import PermutPixel 17 from PermutPixel import PermutPixel
18 #from gimp_script import GIMP1 18 from gimp_script import GIMP1
19 from Rature import Rature 19 from Rature import Rature
20 from contrast import Contrast 20 from contrast import Contrast
21 from local_elastic_distortions import LocalElasticDistorter 21 from local_elastic_distortions import LocalElasticDistorter
22 from slant import Slant 22 from slant import Slant
23 from Occlusion import Occlusion 23 from Occlusion import Occlusion
24 from add_background_image import AddBackground 24 from add_background_image import AddBackground
25 from affine_transform import AffineTransformation 25 from affine_transform import AffineTransformation
26 26
27 ###---------------------order of transformation module 27 ###---------------------order of transformation module
28 MODULE_INSTANCES = [Slant(),Thick(),AffineTransformation(),LocalElasticDistorter(), PermutPixel(), Rature(), Occlusion(), BruitGauss(),PoivreSel(),AddBackground(), Contrast()] 28 MODULE_INSTANCES = [Slant(),Thick(),AffineTransformation(),LocalElasticDistorter(),GIMP1(), PermutPixel(),DistorsionGauss(), Rature(), Occlusion(),AddBackground(), BruitGauss(),PoivreSel(), Contrast()]
29 29
30 ###---------------------complexity associated to each of them 30 ###---------------------complexity associated to each of them
31 complexity = [0.5,0.6,0.5,0.4,0.1,0.5,0.5,0.5,0.5,0.5,0.5] 31 complexity = [0.7,0.7,0.7,0.7,0.7,0.3,0.3,0.5,0.5,0.1,0.3,0.3,0.5]
32 complexity = [0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.] 32 #complexity = [0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
33 33
34 34
35 35
36 nbmodule = len(MODULE_INSTANCES) 36 nbmodule = len(MODULE_INSTANCES)
37 37
41 41
42 d = d[0:1000,:]/255.0 42 d = d[0:1000,:]/255.0
43 43
44 pygame.surfarray.use_arraytype('numpy') 44 pygame.surfarray.use_arraytype('numpy')
45 45
46 pygame.display.init() 46 #pygame.display.init()
47 screen = pygame.display.set_mode((4*(nbmodule+1)/2*32,2*(4*32+20)),0,8) 47 screen = pygame.Surface((4*(nbmodule+1)/2*32,2*(4*32+20)),depth=32)
48
48 anglcolorpalette=[(x,x,x) for x in xrange(0,256)] 49 anglcolorpalette=[(x,x,x) for x in xrange(0,256)]
49 screen.set_palette(anglcolorpalette) 50 #pygame.Surface.set_palette(anglcolorpalette)
51 #screen.set_palette(anglcolorpalette)
50 52
51 pygame.font.init() 53 pygame.font.init()
52 54
53 for i in range(10000): 55 for i in range(10000):
54 a=d[i,:] 56 a=d[i,:]
55 b=N.asarray(N.reshape(a,(32,32))) 57 b=N.asarray(N.reshape(a,(32,32)))
56 c=N.asarray(N.reshape(a*255.0,(32,32))).T 58 c=N.asarray([N.reshape(a*255.0,(32,32))]*3).T
57 new=pygame.surfarray.make_surface(c) 59 new=pygame.surfarray.make_surface(c)
58 new=pygame.transform.scale2x(new) 60 new=pygame.transform.scale2x(new)
59 new=pygame.transform.scale2x(new) 61 new=pygame.transform.scale2x(new)
60 new.set_palette(anglcolorpalette) 62 #new.set_palette(anglcolorpalette)
61 screen.blit(new,(0,0)) 63 screen.blit(new,(0,0))
62 64
63 offset = 4*32 65 offset = 4*32
64 offset2 = 0 66 offset2 = 0
65 ct = 0 67 ct = 0
66 for j in MODULE_INSTANCES: 68 for j in MODULE_INSTANCES:
67 #max dilation 69 #max dilation
68 70
69 #random 71 #random
70 print j.get_settings_names(), j.regenerate_parameters(complexity[ct]) 72 print j.get_settings_names(), j.regenerate_parameters(N.random.rand()*complexity[ct])
71 73
72 b=j.transform_image(b) 74 b=j.transform_image(b)
73 c=N.asarray(b*255).T 75 c=N.asarray([b*255]*3).T
74 76
75 new=pygame.surfarray.make_surface(c) 77 new=pygame.surfarray.make_surface(c)
76 new=pygame.transform.scale2x(new) 78 new=pygame.transform.scale2x(new)
77 new=pygame.transform.scale2x(new) 79 new=pygame.transform.scale2x(new)
78 new.set_palette(anglcolorpalette) 80 #new.set_palette(anglcolorpalette)
79 screen.blit(new,(offset,offset2)) 81 screen.blit(new,(offset,offset2))
80 font = pygame.font.SysFont('liberationserif',18) 82 font = pygame.font.SysFont('liberationserif',18)
81 text = font.render(j.__module__,0,(255,255,255),(0,0,0)) 83 text = font.render(j.__module__,0,(255,255,255),(0,0,0))
82 screen.blit(text,(offset,offset2+4*32)) 84 screen.blit(text,(offset,offset2+4*32))
83 if ct == len(MODULE_INSTANCES)/2-1: 85 if ct == len(MODULE_INSTANCES)/2-1:
84 offset = 0 86 offset = 0
85 offset2 = 4*32+20 87 offset2 = 4*32+20
86 else: 88 else:
87 offset += 4*32 89 offset += 4*32
88 ct+=1 90 ct+=1
89 pygame.display.update() 91 pygame.image.save(screen,'/u/glorotxa/exemples/%s.BMP'%i)
90 raw_input('Press Enter') 92 #raw_input('Press Enter')
91 93
92 pygame.display.quit() 94 #pygame.display.quit()