Source code

Download source archive ↓

upstream/tools/image_processing/imagej2/imagej2_noise.xml

1<tool id="imagej2_noise" name="Add or remove noise" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="23.0">
2    <description>with ImageJ2</description>
3    <macros>
4        <import>imagej2_macros.xml</import>
5    </macros>
6    <edam_operations>
7        <edam_operation>operation_3443</edam_operation>
8    </edam_operations>
9    <xrefs>
10        <xref type="bio.tools">imagej</xref>
11        <xref type="biii">imagej2</xref>
12    </xrefs>
13    <expand macro="fiji_requirements"/>
14    <command detect_errors="exit_code"><![CDATA[
15#import os
16#set input_sans_ext = $os.path.splitext($os.path.basename($input.file_name))[0]
17#set input_with_ext = './' + '.'.join([input_sans_ext, $input.ext])
18ln -s '$input.file_name' '$input_with_ext' &&
19#set output_filename = '.'.join(['output', $input.ext])
20touch '$output_filename' &&
21ImageJ --ij2 --headless --debug
22--jython '$__tool_directory__/imagej2_noise_jython_script.py'
23'$input_with_ext'
24'$input.ext'
25'$noise_cond.noise'
26#if $noise_cond.noise == 'add_specified_noise':
27    $noise_cond.standard_deviation
28#else:
29    'None'
30#end if
31#if $noise_cond.noise == 'remove_outliers':
32    $noise_cond.radius
33    $noise_cond.threshold
34    '$noise_cond.which_outliers'
35#else:
36    'None'
37    'None'
38    'None'
39#end if
40'$output_filename'
41&& mv '$output_filename' '$output';
42]]></command>
43    <inputs>
44        <expand macro="param_input"/>
45        <conditional name="noise_cond">
46            <param name="noise" type="select" label="Noise">
47                <option value="add_noise" selected="True">Add Random Noise</option>
48                <option value="add_specified_noise">Add Specified Noise</option>
49                <option value="salt_and_pepper">Salt and Pepper</option>
50                <option value="despeckle">Despeckle</option>
51                <option value="remove_outliers">Remove Outliers</option>
52                <option value="remove_nans">Remove NaNs</option>
53                <option value="rof_denoise">ROF Denoise</option>
54            </param>
55            <when value="add_noise"/>
56            <when value="add_specified_noise">
57                <param name="standard_deviation" type="float" value="25.0" label="Standard deviation" help="Floating point number"/>
58            </when>
59            <when value="salt_and_pepper"/>
60            <when value="despeckle"/>
61            <when value="remove_outliers">
62                <param name="radius" type="float" value="2.0" label="Radius" help="pixels"/>
63                <param name="threshold" type="float" value="50.0" label="Threshold"/>
64                <param name="which_outliers" type="select" label="Which Outliers">
65                    <option value="Bright" selected="True">Bright</option>
66                    <option value="Dark">Dark</option>
67                </param>
68            </when>
69            <when value="remove_nans"/>
70            <when value="rof_denoise"/>
71        </conditional>
72    </inputs>
73    <outputs>
74        <data name="output" format_source="input"/>
75    </outputs>
76    <tests>
77        <test>
78            <param name="input" value="blobs.gif"/>
79            <conditional name="noise_cond">
80                <param name="noise" value="add_specified_noise"/>
81                <param name="standard_deviation" value="5"/>
82            </conditional>
83            <!-- Cannot use image_diff as the noise is random -->
84            <output name="output" file="add_specified_noise.gif" compare="sim_size"/>
85        </test>
86        <test>
87            <param name="input" value="blobs.gif"/>
88            <conditional name="noise_cond">
89                <param name="noise" value="despeckle"/>
90            </conditional>
91            <output name="output" file="despeckle.gif" compare="image_diff"/>
92        </test>
93        <test>
94            <param name="input" value="blobs.gif"/>
95            <conditional name="noise_cond">
96                <param name="noise" value="remove_outliers"/>
97                <param name="radius" value="10.0"/>
98                <param name="threshold" value="1"/>
99                <param name="which_outliers" value="Bright"/>
100            </conditional>
101            <output name="output" file="remove_outliers.gif" compare="image_diff"/>
102        </test>
103        <test expect_failure="true">
104            <param name="input" value="blobs.gif"/>
105            <conditional name="noise_cond">
106                <param name="noise" value="remove_nans"/>
107            </conditional>
108        </test>
109    </tests>
110    <help>
111**What it does**
112
113<![CDATA[
114Adds noise to or removes noise from images.
115
116- **Add Random Noise** - Adds random noise to the image. The noise is Gaussian (normally) distributed with a mean of zero and standard deviation of 25.
117- **Add Specified Noise** - Adds Gaussian noise with a mean of zero and a chosen standard deviation.
118- **Salt and Pepper** - Adds salt and pepper noise to the image by randomly replacing 2.5% of the pixels with black pixels and 2.5% with white pixels. This command only works with 8-bit images.
119- **Despeckle** - Replaces each pixel with the median value in its 3 × 3 neighborhood. This is a time consuming operation because for each pixel, the nine pixels in the 3 × 3 neighborhood must be sorted and the center pixel replaced with the median value (the fifth).
120- **Remove Outliers** - Replaces a pixel by the median of the pixels in the surrounding if it deviates from the median by more than a certain value (the threshold).
121- **Remove NaNs** - Replaces NaN (Not-a-Number) pixels in 32-bit images by the median of the neighbors inside the circular kernel area defined by Radius. It does not remove patches of NaNs larger than the kernel size, however.
122]]>
123    </help>
124    <expand macro="fiji_headless_citations"/>
125</tool>