annotate data_generation/transformations/contrast.py @ 431:bfa349f567e8

correction in the transformation descripition
author Xavier Glorot <glorotxa@iro.umontreal.ca>
date Mon, 03 May 2010 01:07:21 -0400
parents 1f5937e9e530
children
rev   line source
27
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
1 #!/usr/bin/python
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
2 # coding: utf-8
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
3
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
4 '''
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
5 Simple implementation of random contrast. This always switch half the time the polarity.
31
7ef8aac2cdb5 comment change and useless import removed for contrast.py
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 27
diff changeset
6 then it decides of a random contrast dependant of the complexity, the mean of the maximum and minimum
7ef8aac2cdb5 comment change and useless import removed for contrast.py
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents: 27
diff changeset
7 pixel value stays 0 (to avoid import bias change between exemples).
27
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
8
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
9 Author: Xavier Glorot
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
10 '''
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
11
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
12 import numpy as N
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
13 import copy
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
14
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
15
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
16 class Contrast():
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
17 def __init__(self,complexity = 1):
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
18 #---------- private attributes
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
19 self.__nx__ = 32 #xdim of the images
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
20 self.__ny__ = 32 #ydim of the images
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
21 self.__Pinvert__ = 0.5 #probability to switch polarity
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
22 self.__mincontrast__ = 0.15
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
23 self.__resolution__ = 256
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
24 self.__rangecontrastres__ = self.__resolution__ - N.int(self.__mincontrast__*self.__resolution__)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
25 #------------------------------------------------
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
26
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
27 #---------- generation parameters
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
28 self.regenerate_parameters(complexity)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
29 #------------------------------------------------
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
30
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
31 def _get_current_parameters(self):
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
32 return [self.invert,self.contrast]
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
33
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
34 def get_settings_names(self):
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
35 return ['invert','contrast']
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
36
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
37 def regenerate_parameters(self, complexity):
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
38 self.invert = (N.random.uniform() < self.__Pinvert__)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
39 self.contrast = self.__resolution__ - N.random.randint(1 + self.__rangecontrastres__ * complexity)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
40 return self._get_current_parameters()
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
41
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
42 def transform_1_image(self,image): #the real transformation method
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
43 maxi = image.max()
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
44 mini = image.min()
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
45 if self.invert:
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
46 newimage = 1 - (self.__resolution__- self.contrast) / (2 * float(self.__resolution__)) -\
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
47 (image - mini) / float(maxi - mini) * self.contrast / float(self.__resolution__)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
48 else:
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
49 newimage = (self.__resolution__- self.contrast) / (2 * float(self.__resolution__)) +\
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
50 (image - mini) / float(maxi - mini) * self.contrast / float(self.__resolution__)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
51 if image.dtype == 'uint8':
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
52 return N.asarray(newimage*255,dtype='uint8')
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
53 else:
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
54 return N.asarray(newimage,dtype=image.dtype)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
55
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
56 def transform_image(self,image): #handling different format
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
57 if image.shape == (self.__nx__,self.__ny__):
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
58 return self.transform_1_image(image)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
59 if image.ndim == 3:
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
60 newimage = copy.copy(image)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
61 for i in range(image.shape[0]):
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
62 newimage[i,:,:] = self.transform_1_image(image[i,:,:])
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
63 return newimage
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
64 if image.ndim == 2 and image.shape != (self.__nx__,self.__ny__):
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
65 newimage = N.reshape(image,(image.shape[0],self.__nx__,self.__ny__))
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
66 for i in range(image.shape[0]):
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
67 newimage[i,:,:] = self.transform_1_image(newimage[i,:,:])
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
68 return N.reshape(newimage,image.shape)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
69 if image.ndim == 1:
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
70 newimage = N.reshape(image,(self.__nx__,self.__ny__))
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
71 newimage = self.transform_1_image(newimage)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
72 return N.reshape(newimage,image.shape)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
73 assert False #should never go there
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
74
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
75
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
76
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
77
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
78 #test on NIST (you need pylearn and access to NIST to do that)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
79
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
80 if __name__ == '__main__':
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
81
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
82 from pylearn.io import filetensor as ft
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
83 import copy
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
84 import pygame
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
85 import time
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
86 datapath = '/data/lisa/data/nist/by_class/'
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
87 f = open(datapath+'digits/digits_train_data.ft')
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
88 d = ft.read(f)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
89
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
90 pygame.surfarray.use_arraytype('numpy')
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
91
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
92 pygame.display.init()
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
93 screen = pygame.display.set_mode((8*2*32,8*32),0,8)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
94 anglcolorpalette=[(x,x,x) for x in xrange(0,256)]
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
95 screen.set_palette(anglcolorpalette)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
96
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
97 MyContrast = Contrast()
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
98
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
99 debut=time.time()
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
100 MyContrast.transform_image(d)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
101 fin=time.time()
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
102 print '------------------------------------------------'
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
103 print d.shape[0],' images transformed in :', fin-debut, ' seconds'
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
104 print '------------------------------------------------'
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
105 print (fin-debut)/d.shape[0]*1000000,' microseconds per image'
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
106 print '------------------------------------------------'
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
107 print MyContrast.get_settings_names()
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
108 print MyContrast._get_current_parameters()
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
109 print MyContrast.regenerate_parameters(0)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
110 print MyContrast.regenerate_parameters(0.5)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
111 print MyContrast.regenerate_parameters(1)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
112 for i in range(10000):
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
113 a=d[i,:]
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
114 b=N.asarray(N.reshape(a,(32,32))).T
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
115
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
116 new=pygame.surfarray.make_surface(b)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
117 new=pygame.transform.scale2x(new)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
118 new=pygame.transform.scale2x(new)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
119 new=pygame.transform.scale2x(new)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
120 new.set_palette(anglcolorpalette)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
121 screen.blit(new,(0,0))
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
122
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
123 print MyContrast.get_settings_names(), MyContrast.regenerate_parameters(1)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
124 c=MyContrast.transform_image(a)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
125 b=N.asarray(N.reshape(c,(32,32))).T
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
126
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
127 new=pygame.surfarray.make_surface(b)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
128 new=pygame.transform.scale2x(new)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
129 new=pygame.transform.scale2x(new)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
130 new=pygame.transform.scale2x(new)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
131 new.set_palette(anglcolorpalette)
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
132 screen.blit(new,(8*32,0))
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
133
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
134 pygame.display.update()
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
135 raw_input('Press Enter')
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
136
0b9350998dbe Added a contrast.py script difining the Contrast transformation class
Xavier Glorot <glorotxa@iro.umontreal.ca>
parents:
diff changeset
137 pygame.display.quit()