comparison scale_image.xml @ 4:5122286b700e draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/scale_image/ commit cd908933bd7bd8756c213af57ea6343a90effc12
author imgteam
date Sat, 13 Dec 2025 22:11:13 +0000
parents ba2b1a6f1b84
children
comparison
equal deleted inserted replaced
3:ba2b1a6f1b84 4:5122286b700e
1 <tool id="ip_scale_image" name="Scale image" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.05"> 1 <tool id="ip_scale_image" name="Scale image" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.05">
2 <description>with scikit-image</description> 2 <description>with scikit-image</description>
3 <macros> 3 <macros>
4 <import>creators.xml</import> 4 <import>creators.xml</import>
5 <import>tests.xml</import> 5 <import>tests.xml</import>
6 <token name="@TOOL_VERSION@">0.18.3</token> 6 <token name="@TOOL_VERSION@">0.25.2</token>
7 <token name="@VERSION_SUFFIX@">2</token> 7 <token name="@VERSION_SUFFIX@">0</token>
8 <xml name="factor_input" tokens="name,label">
9 <param name="@NAME@" type="float" min="0.01" max="10" value="1" label="@LABEL@ scaling factor"
10 help="Values less than 1 will down-sample the image data. Values greater than 1 will up-sample the image data."/>
11 </xml>
12 <xml name="anti_alias_input">
13 <param name="anti_alias" type="boolean" truevalue="true" falsevalue="false" checked="true" label="Enable anti-aliasing"
14 help="Disable this when processing binary images or label maps."/>
15 </xml>
8 </macros> 16 </macros>
9 <creator> 17 <creator>
10 <expand macro="creators/bmcv" /> 18 <expand macro="creators/bmcv"/>
19 <expand macro="creators/kostrykin"/>
11 </creator> 20 </creator>
12 <edam_operations> 21 <edam_operations>
13 <edam_operation>operation_3443</edam_operation> 22 <edam_operation>operation_3443</edam_operation>
14 </edam_operations> 23 </edam_operations>
15 <xrefs> 24 <xrefs>
25 <xref type="bio.tools">galaxy_image_analysis</xref>
16 <xref type="bio.tools">scikit-image</xref> 26 <xref type="bio.tools">scikit-image</xref>
17 <xref type="biii">scikit-image</xref> 27 <xref type="biii">scikit-image</xref>
18 </xrefs> 28 </xrefs>
19 <requirements> 29 <requirements>
20 <requirement type="package" version="@TOOL_VERSION@">scikit-image</requirement> 30 <requirement type="package" version="@TOOL_VERSION@">scikit-image</requirement>
21 <requirement type="package" version="10.0.1">pillow</requirement> 31 <requirement type="package" version="2.3.5">numpy</requirement>
22 <requirement type="package" version="1.24.4">numpy</requirement> 32 <requirement type="package" version="0.5.2">giatools</requirement>
23 <requirement type="package" version="2021.7.2">tifffile</requirement> 33 <requirement type="package" version="2025.10.16">tifffile</requirement>
24 <requirement type="package" version="0.1">giatools</requirement>
25 </requirements> 34 </requirements>
26 <command detect_errors="aggressive"><![CDATA[ 35 <command detect_errors="aggressive"><![CDATA[
27 36
28 python '$__tool_directory__/scale_image.py' '$input' 37 python '$__tool_directory__/scale_image.py'
29 38
39 '$input'
30 ./output.${input.ext} 40 ./output.${input.ext}
31 41 '$params'
32 --scale '$scale'
33 --order $order
34 $antialias
35 42
36 && mv ./output.${input.ext} ./output 43 && mv ./output.${input.ext} ./output
37 44
38 ]]></command> 45 ]]></command>
46 <configfiles>
47 <configfile name="params"><![CDATA[
48 {
49
50 #if $scale.mode == "uniform"
51 "axes": "$scale.axes",
52 "factor": $scale.factor,
53
54 #elif $scale.mode == "explicit"
55 "factor_x": $scale.factor_x,
56 "factor_y": $scale.factor_y,
57 "factor_z": $scale.factor_z,
58 "factor_t": $scale.factor_t,
59 "factor_q": $scale.factor_q,
60
61 #elif $scale.mode == "isotropy"
62 "sample": "$scale.sample",
63
64 #end if
65 "mode": "$scale.mode",
66 "order": $interpolation.order,
67 "anti_alias": $interpolation.anti_alias
68
69 }
70 ]]></configfile>
71 </configfiles>
39 <inputs> 72 <inputs>
40 <param name="input" type="data" format="png,tiff" label="Image file"/> 73 <param name="input" type="data" format="png,tiff" label="Input image"/>
41 <param argument="--scale" type="text" value="1" label="Scaling factor" help="Use either a single scaling factor (uniform scaling), or a comma-separated list of scaling factors (anistropic scaling). For a 2-D single-channel or RGB image, the first scaling factor corresponds to the image width and the second corresponds to the image height. For images with 3 or more axes, the last axis is assumed to correspond to the image channels if uniform scaling is used (a single value)."/> 74 <conditional name="scale">
42 <param argument="--order" type="select" label="Interpolation method"> 75 <param name="mode" type="select" label="How to scale?"
43 <option value="0">Nearest-neighbor</option> 76 help='Using the "Scale to spatially isotropic pixels/voxels" option requires that the real-world resolution is available from the metadata of the input image.'>
44 <option value="1" selected="true">Bi-linear</option> 77 <option value="uniform" selected="true">Uniform scaling factor</option>
45 <option value="2">Bi-cubic</option> 78 <option value="explicit">Explicit scaling factors</option>
46 </param> 79 <option value="isotropy">Scale to spatially isotropic pixels/voxels</option>
47 <param name="antialias" type="boolean" truevalue="--antialias" falsevalue="" checked="true" label="Enable anti-aliasing" help="This should only be used for down-scaling."/> 80 </param>
81 <when value="uniform">
82 <param name="axes" type="select" label="Axes to be scaled">
83 <option value="spatial" selected="true">All spatial axes (X, Y, Z)</option>
84 <option value="all">All axes except channels (X, Y, Z, T, Q)</option>
85 </param>
86 <expand macro="factor_input" name="factor" label="Uniform"/>
87 </when>
88 <when value="explicit">
89 <expand macro="factor_input" name="factor_x" label="Horizontal (X)"/>
90 <expand macro="factor_input" name="factor_y" label="Vertical (Y)"/>
91 <expand macro="factor_input" name="factor_z" label="Depth axis (Z)"/>
92 <expand macro="factor_input" name="factor_t" label="Temporal (T)"/>
93 <expand macro="factor_input" name="factor_q" label="Other axis (Q)"/>
94 </when>
95 <when value="isotropy">
96 <param name="sample" type="select" label="Method">
97 <option value="up">Up-sample (enlarges the image data)</option>
98 <option value="down" selected="true">Down-sample (might lose information)</option>
99 </param>
100 </when>
101 </conditional>
102 <conditional name="interpolation">
103 <param name="order" type="select" label="Interpolation method">
104 <option value="0">Nearest-neighbor (good for binary images and label maps)</option>
105 <option value="1" selected="true">Linear (better preserves the intensity values)</option>
106 <option value="2">Cubic (yields visually superior results)</option>
107 </param>
108 <when value="0">
109 <param name="anti_alias" type="hidden" value="false"/>
110 </when>
111 <when value="1">
112 <expand macro="anti_alias_input"/>
113 </when>
114 <when value="2">
115 <expand macro="anti_alias_input"/>
116 </when>
117 </conditional>
48 </inputs> 118 </inputs>
49 <outputs> 119 <outputs>
50 <data name="output" from_work_dir="output" format_source="input" metadata_source="input"/> 120 <data name="output" from_work_dir="output" format_source="input" metadata_source="input"/>
51 </outputs> 121 </outputs>
52 <tests> 122 <tests>
53 <!-- Test PNG, without antialias --> 123 <!-- Test PNG, uniform scaling, nearest neighbor interpolation (without anti-alias) -->
54 <test> 124 <test>
55 <param name="input" value="input1_binary_rgb.png"/> 125 <param name="input" value="inputs/binary_rgba.png"/>
56 <param name="scale" value="0.5"/> 126 <conditional name="scale">
57 <param name="antialias" value="false"/> 127 <param name="mode" value="uniform"/>
58 <param name="order" value="0"/> 128 <param name="factor" value="0.7"/>
59 <expand macro="tests/binary_image_diff" name="output" value="uniform_binary.png" ftype="png"/> 129 </conditional>
60 </test> 130 <conditional name="interpolation">
61 <!-- Test PNG, uniform scaling --> 131 <param name="order" value="0"/>
62 <test> 132 </conditional>
63 <param name="input" value="input1_binary_rgb.png"/> 133 <expand macro="tests/binary_image_diff" name="output" value="outputs/binary_rgba_uniform_down_nn.png" ftype="png"/>
64 <param name="scale" value="0.5"/> 134 <assert_stdout>
65 <expand macro="tests/intensity_image_diff" name="output" value="uniform.png" ftype="png"/> 135 <has_line line="Input axes: YXC"/>
66 </test> 136 <has_line line="Input has no metadata"/>
67 <!-- Test PNG, anistropic scaling --> 137 <has_line line="Output axes: YXC"/>
68 <test> 138 <has_line line="Output resolution: (0.7, 0.7), z_spacing: 1.0"/>
69 <param name="input" value="input1_binary_rgb.png"/> 139 <has_line line="scale: (1, 1, 1, 0.7, 0.7)"/>
70 <param name="scale" value="0.5, 0.8"/> 140 <has_line line="order: 0"/>
71 <expand macro="tests/intensity_image_diff" name="output" value="anisotropic.png" ftype="png"/> 141 <has_line line="anti_aliasing: False"/>
72 </test> 142 </assert_stdout>
73 <test> 143 </test>
74 <param name="input" value="input1_binary_rgb.png"/> 144 <test>
75 <param name="scale" value="0.5, 0.8, 1"/> 145 <param name="input" value="inputs/binary_rgba.png"/>
76 <expand macro="tests/intensity_image_diff" name="output" value="anisotropic.png" ftype="png"/> 146 <conditional name="scale">
77 </test> 147 <param name="mode" value="uniform"/>
78 <!-- Test TIFF, normalized --> 148 <param name="factor" value="1.5"/>
79 <test> 149 </conditional>
80 <param name="input" value="input2_normalized.tiff"/> 150 <conditional name="interpolation">
81 <param name="scale" value="0.5"/> 151 <param name="order" value="0"/>
82 <expand macro="tests/intensity_image_diff" name="output" value="normalized.tiff" ftype="tiff"/> 152 </conditional>
83 </test> 153 <expand macro="tests/binary_image_diff" name="output" value="outputs/binary_rgba_uniform_up_nn.png" ftype="png"/>
84 <!-- Test TIFF, not normalized --> 154 <assert_stdout>
85 <test> 155 <has_line line="Input axes: YXC"/>
86 <param name="input" value="input3_not_normalized.tiff"/> 156 <has_line line="Input has no metadata"/>
87 <param name="scale" value="0.5"/> 157 <has_line line="Output axes: YXC"/>
88 <expand macro="tests/intensity_image_diff" name="output" value="not_normalized.tiff" ftype="tiff"/> 158 <has_line line="Output resolution: (1.5, 1.5), z_spacing: 1.0"/>
159 <has_line line="scale: (1, 1, 1, 1.5, 1.5)"/>
160 <has_line line="order: 0"/>
161 <has_line line="anti_aliasing: False"/>
162 </assert_stdout>
163 </test>
164 <!-- Test PNG, uniform scaling, linear interpolation with anti-alias -->
165 <test>
166 <param name="input" value="inputs/rgb.png"/>
167 <conditional name="scale">
168 <param name="mode" value="uniform"/>
169 <param name="factor" value="0.7"/>
170 </conditional>
171 <conditional name="interpolation">
172 <param name="order" value="1"/>
173 <param name="anti_alias" value="true"/>
174 </conditional>
175 <expand macro="tests/intensity_image_diff" name="output" value="outputs/rgb_uniform_down_linear_aa.png" ftype="png"/>
176 <assert_stdout>
177 <has_line line="Input axes: YXC"/>
178 <has_line line="Input has no metadata"/>
179 <has_line line="Output axes: YXC"/>
180 <has_line line="Output resolution: (0.7, 0.7), z_spacing: 1.0"/>
181 <has_line line="scale: (1, 1, 1, 0.7, 0.7)"/>
182 <has_line line="order: 1"/>
183 <has_line line="anti_aliasing: True"/>
184 <has_line_matching expression="anti_aliasing_sigma: \(0, 0, 0, 0.214[0-9]+, 0.214[0-9]+, 0\)"/>
185 </assert_stdout>
186 </test>
187 <test>
188 <param name="input" value="inputs/rgb.png"/>
189 <conditional name="scale">
190 <param name="mode" value="uniform"/>
191 <param name="factor" value="1.5"/>
192 </conditional>
193 <conditional name="interpolation">
194 <param name="order" value="1"/>
195 <param name="anti_alias" value="true"/>
196 </conditional>
197 <expand macro="tests/intensity_image_diff" name="output" value="outputs/rgb_uniform_up_linear_aa.png" ftype="png"/>
198 <assert_stdout>
199 <has_line line="Input axes: YXC"/>
200 <has_line line="Input has no metadata"/>
201 <has_line line="Output axes: YXC"/>
202 <has_line line="Output resolution: (1.5, 1.5), z_spacing: 1.0"/>
203 <has_line line="scale: (1, 1, 1, 1.5, 1.5)"/>
204 <has_line line="order: 1"/>
205 <has_line line="anti_aliasing: False"/>
206 </assert_stdout>
207 </test>
208 <!-- Test PNG, explicit scaling, cubic interpolation with anti-alias -->
209 <test>
210 <param name="input" value="inputs/binary_rgba.png"/>
211 <conditional name="scale">
212 <param name="mode" value="explicit"/>
213 <param name="factor_x" value="1.5"/>
214 <param name="factor_y" value="0.7"/>
215 <param name="factor_z" value="1.0"/>
216 <param name="factor_t" value="1.0"/>
217 <param name="factor_q" value="1.0"/>
218 </conditional>
219 <conditional name="interpolation">
220 <param name="order" value="2"/>
221 <param name="anti_alias" value="true"/>
222 </conditional>
223 <expand macro="tests/intensity_image_diff" name="output" value="outputs/binary_rgba_explicit_cubic_aa.png" ftype="png"/>
224 <assert_stdout>
225 <has_line line="Input axes: YXC"/>
226 <has_line line="Input has no metadata"/>
227 <has_line line="Output axes: YXC"/>
228 <has_line line="Output resolution: (1.5, 0.7), z_spacing: 1.0"/>
229 <has_line line="scale: (1.0, 1.0, 1.0, 0.7, 1.5)"/>
230 <has_line line="order: 2"/>
231 <has_line line="anti_aliasing: True"/>
232 <has_line_matching expression="anti_aliasing_sigma: \(0, 0, 0, 0.214[0-9]+, 0, 0\)"/>
233 </assert_stdout>
234 </test>
235 <test>
236 <param name="input" value="inputs/binary_rgba.png"/>
237 <conditional name="scale">
238 <param name="mode" value="explicit"/>
239 <param name="factor_x" value="1.5"/>
240 <param name="factor_y" value="0.7"/>
241 <param name="factor_z" value="1.0"/>
242 <param name="factor_t" value="0.1"/>
243 <param name="factor_q" value="1.0"/>
244 </conditional>
245 <conditional name="interpolation">
246 <param name="order" value="2"/>
247 <param name="anti_alias" value="true"/>
248 </conditional>
249 <expand macro="tests/intensity_image_diff" name="output" value="outputs/binary_rgba_explicit_cubic_aa.png" ftype="png"/>
250 <assert_stdout>
251 <has_line line="Input axes: YXC"/>
252 <has_line line="Input has no metadata"/>
253 <has_line line="Output axes: YXC"/>
254 <has_line line="Output resolution: (1.5, 0.7), z_spacing: 1.0"/>
255 <has_line line="scale: (1.0, 0.1, 1.0, 0.7, 1.5)"/>
256 <has_line line="order: 2"/>
257 <has_line line="anti_aliasing: True"/>
258 <has_line_matching expression="anti_aliasing_sigma: \(0, 4.5, 0, 0.214[0-9]+, 0, 0\)"/>
259 </assert_stdout>
260 </test>
261 <test expect_failure="true">
262 <param name="input" value="inputs/binary_rgba.png"/>
263 <conditional name="scale">
264 <param name="mode" value="explicit"/>
265 <param name="factor_x" value="1.5"/>
266 <param name="factor_y" value="0.7"/>
267 <param name="factor_z" value="2.0"/>
268 <param name="factor_t" value="0.1"/>
269 <param name="factor_q" value="1.0"/>
270 </conditional>
271 <conditional name="interpolation">
272 <param name="order" value="2"/>
273 <param name="anti_alias" value="true"/>
274 </conditional>
275 <assert_stderr>
276 <has_line line='Cannot write PNG file with axes "ZYXC"'/>
277 </assert_stderr>
278 </test>
279 <!-- Test TIFF, explicit scaling, cubic interpolation with anti-alias -->
280 <test>
281 <param name="input" value="inputs/binary_c0.tiff"/>
282 <conditional name="scale">
283 <param name="mode" value="explicit"/>
284 <param name="factor_x" value="1.5"/>
285 <param name="factor_y" value="0.7"/>
286 <param name="factor_z" value="2.0"/>
287 <param name="factor_t" value="0.1"/>
288 <param name="factor_q" value="1.0"/>
289 </conditional>
290 <conditional name="interpolation">
291 <param name="order" value="2"/>
292 <param name="anti_alias" value="true"/>
293 </conditional>
294 <expand macro="tests/intensity_image_diff" name="output" value="outputs/binary_c0_explicit_cubic_aa.tiff" ftype="tiff"/>
295 <assert_stdout>
296 <has_line line="Input axes: YX"/>
297 <has_line line="Input resolution: (1.0, 1.0)"/>
298 <has_line line="Output axes: ZYX"/>
299 <has_line line="Output resolution: (1.5, 0.7), z_spacing: 0.5"/>
300 <has_line line="scale: (1.0, 0.1, 2.0, 0.7, 1.5)"/>
301 <has_line line="order: 2"/>
302 <has_line line="anti_aliasing: True"/>
303 <has_line_matching expression="anti_aliasing_sigma: \(0, 4.5, 0, 0.214[0-9]+, 0, 0\)"/>
304 </assert_stdout>
305 </test>
306 <!-- Test TIFF, isotropy scaling, linear interpolation (without anti-alias) -->
307 <test>
308 <param name="input" value="inputs/binary_c2_z10.tiff"/>
309 <conditional name="scale">
310 <param name="mode" value="isotropy"/>
311 <param name="sample" value="up"/>
312 </conditional>
313 <conditional name="interpolation">
314 <param name="order" value="1"/>
315 <param name="anti_alias" value="false"/>
316 </conditional>
317 <expand macro="tests/intensity_image_diff" name="output" value="outputs/binary_c2_z10_isotropy_linear.tiff" ftype="tiff"/>
318 <assert_stdout>
319 <has_line line="Input axes: ZYXC"/>
320 <has_line_matching expression="Input resolution: \(0.1[0-9]*, 0.05[0-9]*\), unit: um, z_spacing: 40.0"/>
321 <has_line line="Output axes: ZYXC"/>
322 <has_line_matching expression="Output resolution: \(0.1[0-9]*, 0.1[0-9]*\), unit: um, z_spacing: (?:9.999[0-9]+|10.0[0-9]*)"/>
323 <has_line_matching expression="scale: \(1, 1, 4.0[0-9]*, 2.0, 1.0\)"/>
324 <has_line line="order: 1"/>
325 <has_line line="anti_aliasing: False"/>
326 </assert_stdout>
327 </test>
328 <test>
329 <param name="input" value="inputs/binary_c2.tiff"/>
330 <conditional name="scale">
331 <param name="mode" value="isotropy"/>
332 <param name="sample" value="up"/>
333 </conditional>
334 <conditional name="interpolation">
335 <param name="order" value="1"/>
336 <param name="anti_alias" value="false"/>
337 </conditional>
338 <expand macro="tests/intensity_image_diff" name="output" value="outputs/binary_c2_isotropy_linear.tiff" ftype="tiff"/>
339 <assert_stdout>
340 <has_line line="Input axes: YXC"/>
341 <has_line_matching expression="Input resolution: \(0.1[0-9]*, 0.05[0-9]*\), unit: um, z_spacing: 40.0"/>
342 <has_line line="Output axes: YXC"/>
343 <has_line_matching expression="Output resolution: \(0.1[0-9]*, 0.1[0-9]*\), unit: um, z_spacing: 40.0"/>
344 <has_line line="scale: (1, 1, 1, 2.0, 1.0)"/>
345 <has_line line="order: 1"/>
346 <has_line line="anti_aliasing: False"/>
347 </assert_stdout>
89 </test> 348 </test>
90 </tests> 349 </tests>
91 <help> 350 <help>
92 351
93 **Scales an image using one or more scaling factors.** 352 **Scales an image by re-sampling the image data.**
94 353
95 The image is rescaled uniformly along all axes, or anistropically if multiple scale factors are given. 354 The image is rescaled uniformly along all axes, or anisotropically if multiple scale factors are given.
355 In addition, the metadata of an image can be used to automatically rescale the image to obtain isotropic pixels or voxels.
96 356
97 This operation preserves both the brightness of the image, and the range of values. 357 This operation preserves both the brightness of the image, and the range of values.
98 358
99 </help> 359 </help>
100 <citations> 360 <citations>