Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1.  
  2. def im_tiles(
  3.     folder,
  4.     im_fmt,
  5.     num_images,
  6.     offset,
  7.     resize,
  8.     s,
  9. ):
  10.     folder = folder
  11.    
  12.     files = glob.glob(os.path.join(folder,'*'+im_fmt))[offset:num_images+offset]
  13.  
  14.     images = np.array([transform.resize(skio.imread(f), resize, order=1)
  15.                        for f in files])
  16.    
  17.     im_tiles = np.array([np.split(np.array(im), s, axis=2) for im in
  18.                          [np.split(im, s, axis=0) for im in images]])
  19.     im_tiles = im_tiles.reshape(im_tiles.shape[0], im_tiles.shape[1]
  20.                                 * im_tiles.shape[2],
  21.                                 *im_tiles.shape[3:]).transpose(1, 0, 2,
  22.                                                                3, 4)
  23.     if num_images > 0:
  24.         im_tiles = np.squeeze(im_tiles)
  25.     else:
  26.         pass
  27.     return im_tiles
  28.  
  29.  
  30.  
  31. def merge_tiles(im_tiles, resize):
  32.     tiles_out_ = []
  33.     for tiles in im_tiles:
  34.  
  35.         tiles = tiles.transpose(3, 1, 2, 0)
  36.         tiles = tiles.reshape(tiles.shape[0], tiles.shape[1] * tiles.shape[2],
  37.                               tiles.shape[3])
  38.         for tile in tiles:
  39.  
  40.             tile_deprocess = np.flipud(tile[:, 0])
  41.             tile_deprocess = tile_deprocess.reshape(
  42.                 im_tiles.shape[2], im_tiles.shape[3])
  43.             tile_deprocess = np.squeeze(tile_deprocess)
  44.             tiles_out_.append(tile_deprocess)
  45.     print(np.array(tiles_out_).shape)
  46.     tiles_out_ = np.array(tiles_out_)
  47.     tiles_out_ = np.split(tiles_out_, im_tiles.shape[0])
  48.  
  49.     tiles_out_ = [np.fliplr(np.dstack(np.fliplr(a))) for a in tiles_out_]
  50.     tiles_out_ = np.rot90(
  51.         util.montage(
  52.             np.transpose(
  53.                 tiles_out_, [
  54.                     0, 2, 1, 3]), multichannel=True), 3)
  55.     tiles_out_ = transform.resize(tiles_out_, resize, order=1)
  56.     showarray(tiles_out_ * 255)
  57.  
  58.     return tiles_out_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement