Repository 'scale_image'
hg clone https://toolshed.g2.bx.psu.edu/repos/thomaswollmann/scale_image

Changeset 0:2d69cbf0f2d2 (2019-01-07)
Commit message:
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/scale_image/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
added:
scale_image.py
scale_image.xml
test-data/out.png
test-data/out2.png
test-data/sample1.png
b
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
b
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 @@
+<tool id="scale_image" name="Scale Image" version="0.2">
+  <description>Scales image</description>
+  <requirements>
+    <requirement type="package" version="0.14.0">scikit-image</requirement>
+    <requirement type="package" version="1.1.0">scipy</requirement>
+  </requirements>
+  <command>
+        <![CDATA[
+        python '$__tool_directory__/scale_image.py' '$input' ./out.png
+        #if $use_scale_option.use_scale == 'true'
+          $use_scale_option.scale
+        #else if $use_scale_option.use_scale == 'false'
+          '[$use_scale_option.scale_x, $use_scale_option.scale_y]'
+        #end if
+        $order
+
+        &&
+        mv ./out.png '$output'
+        ]]>
+  </command>
+  <inputs>
+    <param name="input" type="data" format="png" label="Image file"/>
+    <conditional name="use_scale_option"><!--a third option (using one integer as percentage scaling) could still be implemented-->
+          <param label="Lock scaling between image dimensions" name="use_scale" type="select">
+              <option selected="true" value="true">Lock</option>
+              <option value="false">Individual scales</option>
+          </param>
+          <when value="true">
+            <param name="scale" size="4" type="float" value="1.0" label="Scaling factor" />
+          </when>
+          <when value="false">
+            <param name="scale_x" size="4" type="integer" value="100" label="New height of the image in pixels" />
+            <param name="scale_y" size="4" type="integer" value="100" label="New width of the image in pixels" />
+          </when>
+    </conditional>
+    <param name="order" type="select" label="Interpolation method">
+      <option value="0">Nearest-neighbor</option>
+      <option value="1" selected="true">Bi-linear</option>
+      <option value="2">Bi-cubic</option>
+    </param>
+  </inputs>
+  <outputs>
+    <data format="png" name="output"/>
+  </outputs>
+    <tests>
+      <test>
+        <param name="input" value="sample1.png"/> <!--continue here-->
+        <param name="use_scale_option.use_scale" value="false"/>
+        <param name="use_scale_option.scale_x" value="200"/>
+        <param name="use_scale_option.scale_y" value="150"/>
+        <param name="order" value="0"/>
+        <output name="output" value="out2.png" ftype="png" compare="sim_size"/>
+      </test>
+    </tests>  
+  <help>This tool scales an image using the scaling factor.</help>
+  <citations>
+      <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation>
+  </citations>
+</tool>
b
diff -r 000000000000 -r 2d69cbf0f2d2 test-data/out.png
b
Binary file test-data/out.png has changed
b
diff -r 000000000000 -r 2d69cbf0f2d2 test-data/out2.png
b
Binary file test-data/out2.png has changed
b
diff -r 000000000000 -r 2d69cbf0f2d2 test-data/sample1.png
b
Binary file test-data/sample1.png has changed