Mercurial > repos > imgteam > concat_channels
annotate concat_channels.py @ 1:31c8c700d98d draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit b2acc1845a25828181597fe5b6982fe116a7796d
| author | imgteam | 
|---|---|
| date | Mon, 22 Jul 2019 04:56:23 -0400 | 
| parents | 24d64e0a405f | 
| children | 
| rev | line source | 
|---|---|
| 0 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 1 import argparse | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 2 import sys | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 3 import warnings | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 4 import numpy as np | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 5 import skimage.io | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 6 import skimage.util | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 7 | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 8 def concat_channels(input_image_paths, output_image_path, axis): | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 9 images = [] | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 10 for image_path in input_image_paths: | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 11 raw_image = skimage.io.imread(image_path) | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 12 if len(raw_image.shape) == 2: | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 13 if axis == 0: | 
| 1 
31c8c700d98d
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit b2acc1845a25828181597fe5b6982fe116a7796d
 imgteam parents: 
0diff
changeset | 14 raw_image = [raw_image] | 
| 0 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 15 else: | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 16 raw_image = np.expand_dims(raw_image, 2) | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 17 images.append(raw_image) | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 18 res = np.concatenate(images, axis) | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 19 with warnings.catch_warnings(): | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 20 warnings.simplefilter("ignore") | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 21 res = skimage.util.img_as_uint(res) #Attention: precision loss | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 22 skimage.io.imsave(output_image_path, res, plugin='tifffile') | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 23 | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 24 if __name__ == "__main__": | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 25 parser = argparse.ArgumentParser() | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 26 parser.add_argument('input_files', type=argparse.FileType('r'), nargs='+', help='input file') | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 27 parser.add_argument('-o', dest='out_file', type=argparse.FileType('w'), help='out file (TIFF)') | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 28 parser.add_argument('--axis', dest='axis', type=int, default=0, choices=[0,2], help='concatenation axis') | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 29 args = parser.parse_args() | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 30 | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 31 # print([x.name for x in args.input_files], args.out_file.name, args.axis) | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 32 concat_channels([x.name for x in args.input_files], args.out_file.name, args.axis) | 
| 
24d64e0a405f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
 imgteam parents: diff
changeset | 33 # concat_channels(args.input_files, args.out_file, args.axis) | 
