# HG changeset patch # User thomaswollmann # Date 1546857594 18000 # Node ID 2d69cbf0f2d281dff18068a09b388528a33fa3a6 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/scale_image/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f diff -r 000000000000 -r 2d69cbf0f2d2 scale_image.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scale_image.py Mon Jan 07 05:39:54 2019 -0500 @@ -0,0 +1,44 @@ +import argparse +import sys +import skimage.io +import skimage.transform +import scipy.misc +import warnings +import os +from PIL import Image + + +def scale_image(input_file, output_file, scale, order=1): + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + Image.MAX_IMAGE_PIXELS = 50000*50000 + img_in = skimage.io.imread(input_file) + if order == 0: + interp = 'nearest' + elif order == 1: + interp = 'bilinear' + elif order == 2: + interp = 'bicubic' + + if ',' in scale: + scale = scale[1:-1].split(',') + scale.reverse() + scale = [int(i) for i in scale] + elif '.' in scale: + scale = float(scale) + else: + scale = int(scale) + + res = scipy.misc.imresize(img_in, scale, interp=interp) + skimage.io.imsave(output_file, res) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') + parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (PNG)') + 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 + parser.add_argument('order', type=int, default=1, help='interpolation method') + args = parser.parse_args() + + scale_image(args.input_file.name, args.out_file.name, args.scale, args.order) \ No newline at end of file diff -r 000000000000 -r 2d69cbf0f2d2 scale_image.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scale_image.xml Mon Jan 07 05:39:54 2019 -0500 @@ -0,0 +1,59 @@ + + Scales image + + scikit-image + scipy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This tool scales an image using the scaling factor. + + 10.1016/j.jbiotec.2017.07.019 + + diff -r 000000000000 -r 2d69cbf0f2d2 test-data/out.png Binary file test-data/out.png has changed diff -r 000000000000 -r 2d69cbf0f2d2 test-data/out2.png Binary file test-data/out2.png has changed diff -r 000000000000 -r 2d69cbf0f2d2 test-data/sample1.png Binary file test-data/sample1.png has changed