view filter.xml @ 2:b2d9c92bc431 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_simple_filter/ commit a6fd77be465068f709a71d377900da99becf94d8
author imgteam
date Fri, 12 Dec 2025 21:18:04 +0000
parents e2542d0ac64f
children 53c55776a974
line wrap: on
line source

<tool id="ip_filter_standard" name="Apply 2-D image filter" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.05">
    <description>with scipy</description>
    <macros>
        <import>creators.xml</import>
        <import>tests.xml</import>
        <token name="@TOOL_VERSION@">1.16.3</token>
        <token name="@VERSION_SUFFIX@">0</token>
        <xml name="select_axis">
            <param name="axis" type="select" label="Direction">
                <option value="1" selected="true">Horizontal</option>
                <option value="0">Vertical</option>
            </param>
        </xml>
    </macros>
    <creator>
        <expand macro="creators/bmcv"/>
        <expand macro="creators/kostrykin"/>
    </creator>
    <edam_operations>
        <edam_operation>operation_3443</edam_operation>
    </edam_operations>
    <xrefs>
        <xref type="bio.tools">galaxy_image_analysis</xref>
        <xref type="biii">scipy</xref>
    </xrefs>
    <requirements>
        <requirement type="package" version="@TOOL_VERSION@">scipy</requirement>
        <requirement type="package" version="2.3.5">numpy</requirement>
        <requirement type="package" version="0.25.2">scikit-image</requirement>
        <requirement type="package" version="2025.10.16">tifffile</requirement>
        <requirement type="package" version="0.5.2">giatools</requirement>
    </requirements>
    <command detect_errors="aggressive"><![CDATA[

        python '$__tool_directory__/filter.py'

        '$input'
        '$output'
        '$params'

    ]]></command>
    <configfiles>
        <configfile name="params"><![CDATA[
            {

            ## =====================================================================
            #if $filter.filter_type == "gaussian"
                "sigma": $filter.sigma,
                "order": $filter.derivative.order,

                #if $filter.derivative.order != "0"
                    "axis": $filter.derivative.axis,
                #end if

            ## =====================================================================
            #elif $filter.filter_type == "uniform"
                "size": $filter.size,

            ## =====================================================================
            #elif $filter.filter_type == "median"
                "radius": $filter.radius,

            ## =====================================================================
            #elif $filter.filter_type == "prewitt" or $filter.filter_type == "sobel"
                "axis": $filter.axis,

            ## =====================================================================
            #end if

                "filter_type": "$filter.filter_type"

            }
        ]]></configfile>
    </configfiles>
    <inputs>
        <param name="input" type="data" format="tiff,png" label="Input image"/>
        <conditional name="filter">
            <param name="filter_type" type="select" label="Filter type">
                <option value="gaussian" selected="True">Gaussian</option>
                <option value="uniform">Box filter (uniform filter)</option>
                <option value="median">Median</option>
                <option value="prewitt">Prewitt</option>
                <option value="sobel">Sobel</option>
            </param>
            <when value="gaussian">
                <param name="sigma" type="float" value="3" min="0.1" label="Sigma"
                       help="The half width of the Gaussian bell (in pixels)."/>
                <conditional name="derivative">
                    <param name="order" type="select" label="Use a derivative?">
                        <option value="0">No derivative (mean filter)</option>
                        <option value="1">1st-order derivative</option>
                        <option value="2">2nd-order derivative</option>
                    </param>
                    <when value="0">
                    </when>
                    <when value="1">
                        <expand macro="select_axis"/>
                    </when>
                    <when value="2">
                        <expand macro="select_axis"/>
                    </when>
                </conditional>
            </when>
            <when value="uniform">
                <param name="size" type="integer" min="2" value="3" label="Size"
                       help="Edge length of the neighborhood (square, in pixels)."/>
            </when>
            <when value="median">
                <param name="radius" type="integer" min="2" value="3" label="Radius"
                       help="Radius of the neighborhood (circle, in pixels)." />
            </when>
            <when value="prewitt">
                <expand macro="select_axis"/>
            </when>
            <when value="sobel">
                <expand macro="select_axis"/>
            </when>
        </conditional>
    </inputs>
    <outputs>
       <data format="tiff" name="output" />
    </outputs>
    <tests>
        <!-- Tests with uint8 TIFF input image -->
        <test>
            <param name="input" value="input1_uint8.tiff"/>
            <conditional name="filter">
                <param name="filter_type" value="gaussian"/>
            </conditional>
            <expand macro="tests/intensity_image_diff" name="output" value="input1_gaussian.tiff" ftype="tiff">
                <!--

                The input file `input1_uint8.tiff` has values ranging between 23 and 254, with a mean value of 63.67.

                Below, we use an assertion in addition to the `image_diff` comparison, to ensure that the range of
                values is preserved. The motiviation behind this is that the expectation images are usually checked
                visually, which means that the `image_diff` comparison is likely to ensure that the brightness of
                the image is correct, thus it's good to double-check the range of values (hence the comparably large
                value for `eps`). This also concerns the median filter.

                -->
                <has_image_mean_intensity mean_intensity="63.67" eps="10"/>
            </expand>
        </test>
        <test>
            <param name="input" value="input1_uint8.tiff"/>
            <conditional name="filter">
                <param name="filter_type" value="median"/>
            </conditional>
            <expand macro="tests/intensity_image_diff" name="output" value="input1_median.tiff" ftype="tiff">
                <!-- See note for Gaussian filter above. -->
                <has_image_mean_intensity mean_intensity="63.67" eps="10"/>
            </expand>
        </test>
        <test>
            <param name="input" value="input1_uint8.tiff"/>
            <conditional name="filter">
                <param name="filter_type" value="prewitt"/>
                <param name="axis" value="1"/>
            </conditional>
            <expand macro="tests/intensity_image_diff" name="output" value="input1_prewitt_h.tiff" ftype="tiff"/>
        </test>
        <test>
            <param name="input" value="input1_uint8.tiff"/>
            <conditional name="filter">
                <param name="filter_type" value="prewitt"/>
                <param name="axis" value="0"/>
            </conditional>
            <expand macro="tests/intensity_image_diff" name="output" value="input1_prewitt_v.tiff" ftype="tiff"/>
        </test>
        <test>
            <param name="input" value="input1_uint8.tiff"/>
            <conditional name="filter">
                <param name="filter_type" value="sobel"/>
                <param name="axis" value="1"/>
            </conditional>
            <expand macro="tests/intensity_image_diff" name="output" value="input1_sobel_h.tiff" ftype="tiff"/>
        </test>
        <test>
            <param name="input" value="input1_uint8.tiff"/>
            <conditional name="filter">
                <param name="filter_type" value="sobel"/>
                <param name="axis" value="0"/>
            </conditional>
            <expand macro="tests/intensity_image_diff" name="output" value="input1_sobel_v.tiff" ftype="tiff"/>
        </test>
        <!-- Tests with float TIFF input image -->
        <test>
            <param name="input" value="input2_float.tiff"/>
            <conditional name="filter">
                <param name="filter_type" value="gaussian"/>
            </conditional>
            <expand macro="tests/intensity_image_diff" name="output" value="input2_gaussian.tiff" ftype="tiff">
                <!-- See note for Gaussian filter above. -->
                <has_image_mean_intensity mean_intensity="0.25" eps="0.01"/>
            </expand>
        </test>
        <test>
            <param name="input" value="input2_float.tiff"/>
            <conditional name="filter">
                <param name="filter_type" value="uniform"/>
                <param name="size" value="4"/>
            </conditional>
            <expand macro="tests/intensity_image_diff" name="output" value="input2_uniform.tiff" ftype="tiff">
                <!-- See note for Gaussian filter above. -->
                <has_image_mean_intensity mean_intensity="0.25" eps="0.01"/>
            </expand>
        </test>
        <!-- Tests with multi-channel image (RGB) -->
        <test>
            <param name="input" value="scikit-image/retina.png"/>
            <conditional name="filter">
                <param name="filter_type" value="gaussian"/>
                <param name="sigma" value="5"/>
                <conditional name="derivative">
                    <param name="order" value="0"/>
                </conditional>
            </conditional>
            <expand macro="tests/intensity_image_diff" name="output" value="retina_gaussian_order0.tiff" ftype="tiff"/>
        </test>
        <test>
            <param name="input" value="scikit-image/retina.png"/>
            <conditional name="filter">
                <param name="filter_type" value="gaussian"/>
                <param name="sigma" value="3"/>
                <conditional name="derivative">
                    <param name="order" value="2"/>
                    <param name="axis" value="0"/>
                </conditional>
            </conditional>
            <expand macro="tests/intensity_image_diff" name="output" value="retina_gaussian_order2_axis0.tiff" ftype="tiff"/>
        </test>
    </tests>
    <help>

        **Applies a standard, general-purpose 2-D filter to an image.**

        Support for different image types:

        - For 3-D images, the filter is applied to all z-slices of the image.
        - For multi-channel images, the filter is applied to all channels of the image.
        - For time-series images, the filter is also applied for all time steps.

        Mean filters like the Gaussian filter, the box filter, or the median filter preserve both the brightness of the image, and
        the range of values. This does not hold for the derivative variants of the Gaussian filter, which may produce negative values.

    </help>
    <citations>
       <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation>
    </citations>
</tool>