Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def im_tiles(
- folder,
- im_fmt,
- num_images,
- offset,
- resize,
- s,
- ):
- folder = folder
- files = glob.glob(os.path.join(folder,'*'+im_fmt))[offset:num_images+offset]
- images = np.array([transform.resize(skio.imread(f), resize, order=1)
- for f in files])
- im_tiles = np.array([np.split(np.array(im), s, axis=2) for im in
- [np.split(im, s, axis=0) for im in images]])
- im_tiles = im_tiles.reshape(im_tiles.shape[0], im_tiles.shape[1]
- * im_tiles.shape[2],
- *im_tiles.shape[3:]).transpose(1, 0, 2,
- 3, 4)
- if num_images > 0:
- im_tiles = np.squeeze(im_tiles)
- else:
- pass
- return im_tiles
- def merge_tiles(im_tiles, resize):
- tiles_out_ = []
- for tiles in im_tiles:
- tiles = tiles.transpose(3, 1, 2, 0)
- tiles = tiles.reshape(tiles.shape[0], tiles.shape[1] * tiles.shape[2],
- tiles.shape[3])
- for tile in tiles:
- tile_deprocess = np.flipud(tile[:, 0])
- tile_deprocess = tile_deprocess.reshape(
- im_tiles.shape[2], im_tiles.shape[3])
- tile_deprocess = np.squeeze(tile_deprocess)
- tiles_out_.append(tile_deprocess)
- print(np.array(tiles_out_).shape)
- tiles_out_ = np.array(tiles_out_)
- tiles_out_ = np.split(tiles_out_, im_tiles.shape[0])
- tiles_out_ = [np.fliplr(np.dstack(np.fliplr(a))) for a in tiles_out_]
- tiles_out_ = np.rot90(
- util.montage(
- np.transpose(
- tiles_out_, [
- 0, 2, 1, 3]), multichannel=True), 3)
- tiles_out_ = transform.resize(tiles_out_, resize, order=1)
- showarray(tiles_out_ * 255)
- return tiles_out_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement