comparison scale_image.py @ 3:d09507d3fb0e draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/scale_image/ commit 6b687746bdb3d5d1fb11ecffd6dd1bf42dc2c38d
author imgteam
date Fri, 10 Nov 2023 14:23:33 +0000
parents f3c05a734dd1
children 3179853faae9
comparison
equal deleted inserted replaced
2:f3c05a734dd1 3:d09507d3fb0e
1 import argparse 1 import argparse
2 import sys 2 import sys
3
4 import scipy.misc
3 import skimage.io 5 import skimage.io
4 import skimage.transform 6 import skimage.transform
5 import scipy.misc
6 from PIL import Image 7 from PIL import Image
7 8
8 9
9 def scale_image(input_file, output_file, scale, order=1): 10 def scale_image(input_file, output_file, scale, order=1):
10 Image.MAX_IMAGE_PIXELS = 50000*50000 11 Image.MAX_IMAGE_PIXELS = 50000 * 50000
11 img_in = skimage.io.imread(input_file) 12 img_in = skimage.io.imread(input_file)
12 if order == 0: 13 if order == 0:
13 interp = 'nearest' 14 interp = 'nearest'
14 elif order == 1: 15 elif order == 1:
15 interp = 'bilinear' 16 interp = 'bilinear'
27 28
28 29
29 if __name__ == "__main__": 30 if __name__ == "__main__":
30 parser = argparse.ArgumentParser() 31 parser = argparse.ArgumentParser()
31 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') 32 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file')
32 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (PNG)') 33 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (PNG)')
33 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 34 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
34 parser.add_argument('order', type=int, default=1, help='interpolation method') 35 parser.add_argument('order', type=int, default=1, help='interpolation method')
35 args = parser.parse_args() 36 args = parser.parse_args()
36 37
37 scale_image(args.input_file.name, args.out_file.name, args.scale, args.order) 38 scale_image(args.input_file.name, args.out_file.name, args.scale, args.order)