def load_sprite_image(img_path, rows_cols, n_sprites=None):
 (rows, cols) = rows_cols
 if (n_sprites is None):
  n_sprites = (rows * cols)
 img = caffe_load_image(img_path, color=True, as_uint=True)
 assert ((img.shape[0] % rows) == 0), ('sprite image has shape %s which is not divisible by rows_cols %' % (img.shape, rows_cols))
 assert ((img.shape[1] % cols) == 0), ('sprite image has shape %s which is not divisible by rows_cols %' % (img.shape, rows_cols))
 sprite_height = (img.shape[0] / rows)
 sprite_width = (img.shape[1] / cols)
 sprite_channels = img.shape[2]
 ret = np.zeros((n_sprites, sprite_height, sprite_width, sprite_channels), dtype=img.dtype)
 for idx in xrange(n_sprites):
  ii = (idx / cols)
  jj = (idx % cols)
  ret[idx] = img[(ii * sprite_height):((ii + 1) * sprite_height), (jj * sprite_width):((jj + 1) * sprite_width), :]
 return ret

def load_sprite_image ( img_path , rows_cols , n_sprites = None ) : ( rows , cols ) = rows_cols if ( n_sprites is None ) : n_sprites = ( rows * cols ) img = caffe_load_image ( img_path , color = True , as_uint = True ) assert ( ( img . shape [ 0 ] % rows ) == 0 ) , ( 'sprite image has shape %s which is not divisible by rows_cols %' % ( img . shape , rows_cols ) ) assert ( ( img . shape [ 1 ] % cols ) == 0 ) , ( 'sprite image has shape %s which is not divisible by rows_cols %' % ( img . shape , rows_cols ) ) sprite_height = ( img . shape [ 0 ] / rows ) sprite_width = ( img . shape [ 1 ] / cols ) sprite_channels = img . shape [ 2 ] ret = np . zeros ( ( n_sprites , sprite_height , sprite_width , sprite_channels ) , dtype = img . dtype ) for idx in xrange ( n_sprites ) : ii = ( idx / cols ) jj = ( idx % cols ) ret [ idx ] = img [ ( ii * sprite_height ) : ( ( ii + 1 ) * sprite_height ) , ( jj * sprite_width ) : ( ( jj + 1 ) * sprite_width ) , : ] return ret
load a 2d sprite image where = rows_cols .