comparison pylearn/io/image_tiling.py @ 1473:91a475ca9b6d

image_tiling with better scaling for integer inputs
author James Bergstra <bergstrj@iro.umontreal.ca>
date Wed, 18 May 2011 10:52:22 -0400
parents 9d941cd77479
children
comparison
equal deleted inserted replaced
1472:ddda8d93c162 1473:91a475ca9b6d
97 return out_array 97 return out_array
98 98
99 else: 99 else:
100 H, W = img_shape 100 H, W = img_shape
101 Hs, Ws = tile_spacing 101 Hs, Ws = tile_spacing
102
103 out_scaling = 1
104 if output_pixel_vals and str(X.dtype).startswith('float'):
105 out_scaling = 255
102 106
103 out_array = numpy.zeros(out_shape, dtype='uint8' if output_pixel_vals else X.dtype) 107 out_array = numpy.zeros(out_shape, dtype='uint8' if output_pixel_vals else X.dtype)
104 for tile_row in xrange(tile_shape[0]): 108 for tile_row in xrange(tile_shape[0]):
105 for tile_col in xrange(tile_shape[1]): 109 for tile_col in xrange(tile_shape[1]):
106 if tile_row * tile_shape[1] + tile_col < X.shape[0]: 110 if tile_row * tile_shape[1] + tile_col < X.shape[0]:
119 this_img = X[tile_row * tile_shape[1] + tile_col].reshape(img_shape) 123 this_img = X[tile_row * tile_shape[1] + tile_col].reshape(img_shape)
120 out_array[ 124 out_array[
121 tile_row * (H+Hs):tile_row*(H+Hs)+H, 125 tile_row * (H+Hs):tile_row*(H+Hs)+H,
122 tile_col * (W+Ws):tile_col*(W+Ws)+W 126 tile_col * (W+Ws):tile_col*(W+Ws)+W
123 ] \ 127 ] \
124 = this_img * (255 if output_pixel_vals else 1) 128 = this_img * out_scaling
125 return out_array 129 return out_array
126 130
127 131
128 def most_square_shape(N): 132 def most_square_shape(N):
129 """rectangle (height, width) with area N that is closest to sqaure 133 """rectangle (height, width) with area N that is closest to sqaure