Mercurial > ift6266
comparison transformations/local_elastic_distortions.py @ 29:b67d729ebfe3
Adapted to avoid saving parameters completely determined by complexity
author | fsavard <francois.savard@polymtl.ca> |
---|---|
date | Fri, 29 Jan 2010 17:16:04 -0500 |
parents | 010e826b41e8 |
children | a8ac3402eb45 |
comparison
equal
deleted
inserted
replaced
28:e5ee2c9a9517 | 29:b67d729ebfe3 |
---|---|
104 # at random and set parameters to match what they were | 104 # at random and set parameters to match what they were |
105 # when the field was generated | 105 # when the field was generated |
106 idx = numpy.random.randint(0, len(self.precomputed_params)) | 106 idx = numpy.random.randint(0, len(self.precomputed_params)) |
107 self.current_params = self.precomputed_params[idx] | 107 self.current_params = self.precomputed_params[idx] |
108 | 108 |
109 return self.current_params.alpha_sigma() | 109 # don't return anything, to avoid storing deterministic parameters |
110 return [] # self.current_params.alpha_sigma() | |
111 | |
112 def get_parameters_determined_by_complexity(self, complexity): | |
113 tmp_params = self._initialize_new_params(complexity) | |
114 return tmp_params.alpha_sigma() | |
110 | 115 |
111 # adapted from http://blenderartists.org/forum/showthread.php?t=163361 | 116 # adapted from http://blenderartists.org/forum/showthread.php?t=163361 |
112 def _gen_gaussian_kernel(self, sigma): | 117 def _gen_gaussian_kernel(self, sigma): |
113 # the kernel size can change DRAMATICALLY the time | 118 # the kernel size can change DRAMATICALLY the time |
114 # for the blur operation... so even though results are better | 119 # for the blur operation... so even though results are better |
145 field = field[ks0:ks0+self.image_size[0], ks1:ks1+self.image_size[1]] | 150 field = field[ks0:ks0+self.image_size[0], ks1:ks1+self.image_size[1]] |
146 | 151 |
147 return params.alpha * field | 152 return params.alpha * field |
148 | 153 |
149 | 154 |
150 def _initialize_new_params(self): | 155 def _initialize_new_params(self, complexity=None): |
156 if not complexity: | |
157 complexity = self.current_complexity | |
158 | |
151 params = ElasticDistortionParams(self.image_size) | 159 params = ElasticDistortionParams(self.image_size) |
152 | 160 |
153 cpx = self.current_complexity | |
154 # pour faire progresser la complexité un peu plus vite | 161 # pour faire progresser la complexité un peu plus vite |
155 # tout en gardant les extrêmes de 0.0 et 1.0 | 162 # tout en gardant les extrêmes de 0.0 et 1.0 |
156 cpx = cpx ** (1./3.) | 163 complexity = complexity ** (1./3.) |
157 | 164 |
158 # the smaller the alpha, the closest the pixels are fetched | 165 # the smaller the alpha, the closest the pixels are fetched |
159 # a max of 10 is reasonable | 166 # a max of 10 is reasonable |
160 params.alpha = cpx * 10.0 | 167 params.alpha = complexity * 10.0 |
161 | 168 |
162 # the bigger the sigma, the smoother is the distortion | 169 # the bigger the sigma, the smoother is the distortion |
163 # max of 1 is "reasonable", but produces VERY noisy results | 170 # max of 1 is "reasonable", but produces VERY noisy results |
164 # And the bigger the sigma, the bigger the blur kernel, and the | 171 # And the bigger the sigma, the bigger the blur kernel, and the |
165 # slower the field generation, btw. | 172 # slower the field generation, btw. |
166 params.sigma = 10.0 - (7.0 * cpx) | 173 params.sigma = 10.0 - (7.0 * complexity) |
167 | 174 |
168 return params | 175 return params |
169 | 176 |
170 def _generate_fields(self, params): | 177 def _generate_fields(self, params): |
171 ''' | 178 ''' |
306 def _specific_test(): | 313 def _specific_test(): |
307 imgpath = os.path.join(_TEST_DIR, "d.png") | 314 imgpath = os.path.join(_TEST_DIR, "d.png") |
308 img = _load_image(imgpath) | 315 img = _load_image(imgpath) |
309 dist = LocalElasticDistorter((32,32)) | 316 dist = LocalElasticDistorter((32,32)) |
310 print dist.regenerate_parameters(0.5) | 317 print dist.regenerate_parameters(0.5) |
311 img = dist.distort_image(img) | 318 img = dist.transform_image(img) |
319 print dist.get_parameters_determined_by_complexity(0.4) | |
312 pylab.imshow(img) | 320 pylab.imshow(img) |
313 pylab.show() | 321 pylab.show() |
314 | 322 |
315 def _complexity_tests(): | 323 def _complexity_tests(): |
316 imgpath = os.path.join(_TEST_DIR, "d.png") | 324 imgpath = os.path.join(_TEST_DIR, "d.png") |
417 import pylab | 425 import pylab |
418 import Image | 426 import Image |
419 import os.path | 427 import os.path |
420 #_distorter_tests() | 428 #_distorter_tests() |
421 #_benchmark() | 429 #_benchmark() |
422 #_specific_test() | 430 _specific_test() |
423 #_complexity_tests() | 431 #_complexity_tests() |
424 _complexity_benchmark() | 432 #_complexity_benchmark() |
425 | 433 |
426 | 434 |
435 |