Mercurial > ift6266
comparison transformations/local_elastic_distortions.py @ 30:a8ac3402eb45
Correction aux distortions élastiques (retourne float32) suite à tests avec testmod.py
author | fsavard <francois.savard@polymtl.ca> |
---|---|
date | Mon, 01 Feb 2010 08:54:10 -0500 |
parents | b67d729ebfe3 |
children | c89defea1e65 |
comparison
equal
deleted
inserted
replaced
29:b67d729ebfe3 | 30:a8ac3402eb45 |
---|---|
27 | 27 |
28 def _raw_zeros(size): | 28 def _raw_zeros(size): |
29 return [[0 for i in range(size[1])] for j in range(size[0])] | 29 return [[0 for i in range(size[1])] for j in range(size[0])] |
30 | 30 |
31 class ElasticDistortionParams(): | 31 class ElasticDistortionParams(): |
32 def __init__(self, image_size, alpha=0.0, sigma=0.0): | 32 def __init__(self, image_size=(32,32), alpha=0.0, sigma=0.0): |
33 self.image_size = image_size | 33 self.image_size = image_size |
34 self.alpha = alpha | 34 self.alpha = alpha |
35 self.sigma = sigma | 35 self.sigma = sigma |
36 | 36 |
37 h,w = self.image_size | 37 h,w = self.image_size |
57 | 57 |
58 def alpha_sigma(self): | 58 def alpha_sigma(self): |
59 return [self.alpha, self.sigma] | 59 return [self.alpha, self.sigma] |
60 | 60 |
61 class LocalElasticDistorter(): | 61 class LocalElasticDistorter(): |
62 def __init__(self, image_size): | 62 def __init__(self, image_size=(32,32)): |
63 self.image_size = image_size | 63 self.image_size = image_size |
64 | 64 |
65 self.current_complexity = 0.0 | 65 self.current_complexity = 0.0 |
66 | 66 |
67 # number of precomputed fields | 67 # number of precomputed fields |
296 tr_pixels = numpy.multiply(tr_pixels, p.matrix_tr_multiply) | 296 tr_pixels = numpy.multiply(tr_pixels, p.matrix_tr_multiply) |
297 bl_pixels = numpy.multiply(bl_pixels, p.matrix_bl_multiply) | 297 bl_pixels = numpy.multiply(bl_pixels, p.matrix_bl_multiply) |
298 br_pixels = numpy.multiply(br_pixels, p.matrix_br_multiply) | 298 br_pixels = numpy.multiply(br_pixels, p.matrix_br_multiply) |
299 | 299 |
300 # sum to finish bilinear combination | 300 # sum to finish bilinear combination |
301 return numpy.sum([tl_pixels,tr_pixels,bl_pixels,br_pixels], axis=0) | 301 return numpy.sum([tl_pixels,tr_pixels,bl_pixels,br_pixels], axis=0).astype(numpy.float32) |
302 | 302 |
303 # TESTS ---------------------------------------------------------------------- | 303 # TESTS ---------------------------------------------------------------------- |
304 | 304 |
305 def _load_image(filepath): | 305 def _load_image(filepath): |
306 _RGB_TO_GRAYSCALE = [0.3, 0.59, 0.11, 0.0] | 306 _RGB_TO_GRAYSCALE = [0.3, 0.59, 0.11, 0.0] |