# HG changeset patch
# User imgteam
# Date 1712244383 0
# Node ID 3179853faae9e7385dee97066f481dff72c7ed7b
# Parent d09507d3fb0e71e6807f6066f4bf240109958b12
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/scale_image/ commit c045f067a57e8308308cf6329060c7ccd3fc372f
diff -r d09507d3fb0e -r 3179853faae9 creators.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/creators.xml Thu Apr 04 15:26:23 2024 +0000
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r d09507d3fb0e -r 3179853faae9 scale_image.py
--- a/scale_image.py Fri Nov 10 14:23:33 2023 +0000
+++ b/scale_image.py Thu Apr 04 15:26:23 2024 +0000
@@ -1,38 +1,50 @@
import argparse
import sys
-import scipy.misc
+import numpy as np
import skimage.io
import skimage.transform
+import skimage.util
from PIL import Image
-def scale_image(input_file, output_file, scale, order=1):
+def scale_image(input_file, output_file, scale, order, antialias):
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'
+ im = skimage.io.imread(input_file)
+
+ # Parse `--scale` argument
if ',' in scale:
- scale = scale[1:-1].split(',')
- scale = [int(i) for i in scale]
- elif '.' in scale:
+ scale = [float(s.strip()) for s in scale.split(',')]
+ assert len(scale) <= im.ndim, f'Image has {im.ndim} axes, but scale factors were given for {len(scale)} axes.'
+ scale = scale + [1] * (im.ndim - len(scale))
+
+ else:
scale = float(scale)
- else:
- scale = int(scale)
- res = scipy.misc.imresize(img_in, scale, interp=interp)
+
+ # For images with 3 or more axes, the last axis is assumed to correspond to channels
+ if im.ndim >= 3:
+ scale = [scale] * (im.ndim - 1) + [1]
+
+ # Do the scaling
+ res = skimage.transform.rescale(im, scale, order, anti_aliasing=antialias, preserve_range=True)
+
+ # Preserve the `dtype` so that both brightness and range of values is preserved
+ if res.dtype != im.dtype:
+ if np.issubdtype(im.dtype, np.integer):
+ res = res.round()
+ res = res.astype(im.dtype)
+
+ # Save result
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')
+ parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin)
+ parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin)
+ parser.add_argument('--scale', type=str, required=True)
+ parser.add_argument('--order', type=int, required=True)
+ parser.add_argument('--antialias', default=False, action='store_true')
args = parser.parse_args()
- scale_image(args.input_file.name, args.out_file.name, args.scale, args.order)
+ scale_image(args.input_file.name, args.out_file.name, args.scale, args.order, args.antialias)
diff -r d09507d3fb0e -r 3179853faae9 scale_image.xml
--- a/scale_image.xml Fri Nov 10 14:23:33 2023 +0000
+++ b/scale_image.xml Thu Apr 04 15:26:23 2024 +0000
@@ -1,5 +1,14 @@
-
+
with scikit-image
+
+ creators.xml
+ tests.xml
+ 0.18.3
+ 0
+
+
+
+
operation_3443
@@ -8,64 +17,84 @@
scikit-image
- pillow
- scikit-image
- numpy
- scipy
- tifffile
+ scikit-image
+ pillow
+ numpy
+ tifffile
-
-
-
+ --scale '$scale'
+ --order $order
+ $antialias
+
+ && mv ./output.${input.ext} ./output
+
+ ]]>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
+
+
-
-
-
-
-
-
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- **What it does**
+
+ **Scales an image using one or more scaling factors.**
- This tool scales an image using the scaling factor.
+ The image is rescaled uniformly along all axes, or anistropically if multiple scale factors are given.
+
+ This operation preserves both the brightness of the image, and the range of values.
+
10.1016/j.jbiotec.2017.07.019
diff -r d09507d3fb0e -r 3179853faae9 test-data/anisotropic.png
Binary file test-data/anisotropic.png has changed
diff -r d09507d3fb0e -r 3179853faae9 test-data/input1_binary_rgb.png
Binary file test-data/input1_binary_rgb.png has changed
diff -r d09507d3fb0e -r 3179853faae9 test-data/input2_normalized.tiff
Binary file test-data/input2_normalized.tiff has changed
diff -r d09507d3fb0e -r 3179853faae9 test-data/input3_not_normalized.tiff
Binary file test-data/input3_not_normalized.tiff has changed
diff -r d09507d3fb0e -r 3179853faae9 test-data/normalized.tiff
Binary file test-data/normalized.tiff has changed
diff -r d09507d3fb0e -r 3179853faae9 test-data/not_normalized.tiff
Binary file test-data/not_normalized.tiff has changed
diff -r d09507d3fb0e -r 3179853faae9 test-data/out.png
Binary file test-data/out.png has changed
diff -r d09507d3fb0e -r 3179853faae9 test-data/out2.png
Binary file test-data/out2.png has changed
diff -r d09507d3fb0e -r 3179853faae9 test-data/sample1.png
Binary file test-data/sample1.png has changed
diff -r d09507d3fb0e -r 3179853faae9 test-data/uniform.png
Binary file test-data/uniform.png has changed
diff -r d09507d3fb0e -r 3179853faae9 test-data/uniform_binary.png
Binary file test-data/uniform_binary.png has changed
diff -r d09507d3fb0e -r 3179853faae9 tests.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests.xml Thu Apr 04 15:26:23 2024 +0000
@@ -0,0 +1,95 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+