Mercurial > repos > imgteam > scale_image
comparison scale_image.py @ 0:c4c76f1ebad2 draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/scale_image/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
author | imgteam |
---|---|
date | Sat, 09 Feb 2019 14:46:03 -0500 |
parents | |
children | 3e4231ed875e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c4c76f1ebad2 |
---|---|
1 import argparse | |
2 import sys | |
3 import skimage.io | |
4 import skimage.transform | |
5 import scipy.misc | |
6 import warnings | |
7 import os | |
8 from PIL import Image | |
9 | |
10 | |
11 def scale_image(input_file, output_file, scale, order=1): | |
12 with warnings.catch_warnings(): | |
13 warnings.simplefilter("ignore") | |
14 Image.MAX_IMAGE_PIXELS = 50000*50000 | |
15 img_in = skimage.io.imread(input_file) | |
16 if order == 0: | |
17 interp = 'nearest' | |
18 elif order == 1: | |
19 interp = 'bilinear' | |
20 elif order == 2: | |
21 interp = 'bicubic' | |
22 | |
23 if ',' in scale: | |
24 scale = scale[1:-1].split(',') | |
25 scale.reverse() | |
26 scale = [int(i) for i in scale] | |
27 elif '.' in scale: | |
28 scale = float(scale) | |
29 else: | |
30 scale = int(scale) | |
31 | |
32 res = scipy.misc.imresize(img_in, scale, interp=interp) | |
33 skimage.io.imsave(output_file, res) | |
34 | |
35 | |
36 if __name__ == "__main__": | |
37 parser = argparse.ArgumentParser() | |
38 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') | |
39 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (PNG)') | |
40 parser.add_argument('scale', type=str, help='fraction scaling factor(float), percentage scaling factor(int), output size(tuple(height,width))') # integer option not implemented in galaxy wrapper | |
41 parser.add_argument('order', type=int, default=1, help='interpolation method') | |
42 args = parser.parse_args() | |
43 | |
44 scale_image(args.input_file.name, args.out_file.name, args.scale, args.order) |