Mercurial > repos > imgteam > scale_image
comparison scale_image.py @ 2:ac497ba6819d draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/scale_image/ commit b2acc1845a25828181597fe5b6982fe116a7796d
author | imgteam |
---|---|
date | Mon, 22 Jul 2019 04:59:15 -0400 |
parents | f0de74fc251d |
children | ba2b1a6f1b84 |
comparison
equal
deleted
inserted
replaced
1:f0de74fc251d | 2:ac497ba6819d |
---|---|
1 import argparse | 1 import argparse |
2 import sys | 2 import sys |
3 import skimage.io | 3 import skimage.io |
4 import skimage.transform | 4 import skimage.transform |
5 import scipy.misc | 5 import scipy.misc |
6 import warnings | |
7 import os | |
8 from PIL import Image | 6 from PIL import Image |
9 | 7 |
10 | 8 |
11 def scale_image(input_file, output_file, scale, order=1): | 9 def scale_image(input_file, output_file, scale, order=1): |
12 with warnings.catch_warnings(): | 10 Image.MAX_IMAGE_PIXELS = 50000*50000 |
13 warnings.simplefilter("ignore") | 11 img_in = skimage.io.imread(input_file) |
14 Image.MAX_IMAGE_PIXELS = 50000*50000 | 12 if order == 0: |
15 img_in = skimage.io.imread(input_file) | 13 interp = 'nearest' |
16 if order == 0: | 14 elif order == 1: |
17 interp = 'nearest' | 15 interp = 'bilinear' |
18 elif order == 1: | 16 elif order == 2: |
19 interp = 'bilinear' | 17 interp = 'bicubic' |
20 elif order == 2: | 18 if ',' in scale: |
21 interp = 'bicubic' | 19 scale = scale[1:-1].split(',') |
22 | 20 scale = [int(i) for i in scale] |
23 if ',' in scale: | 21 elif '.' in scale: |
24 scale = scale[1:-1].split(',') | 22 scale = float(scale) |
25 scale = [int(i) for i in scale] | 23 else: |
26 elif '.' in scale: | 24 scale = int(scale) |
27 scale = float(scale) | 25 res = scipy.misc.imresize(img_in, scale, interp=interp) |
28 else: | 26 skimage.io.imsave(output_file, res) |
29 scale = int(scale) | |
30 | |
31 res = scipy.misc.imresize(img_in, scale, interp=interp) | |
32 skimage.io.imsave(output_file, res) | |
33 | 27 |
34 | 28 |
35 if __name__ == "__main__": | 29 if __name__ == "__main__": |
36 parser = argparse.ArgumentParser() | 30 parser = argparse.ArgumentParser() |
37 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') | 31 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') |