view image_math.xml @ 2:48fa3ac55df2 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/image_math commit c86a1b93cb7732f7331a981d13465653cc1a2790
author imgteam
date Wed, 24 Apr 2024 08:12:29 +0000
parents f8b7770cbca5
children
line wrap: on
line source

<tool id="image_math" name="Process images using arithmetic expressions" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="23.0">
    <description>with NumPy</description>
    <macros>
        <import>creators.xml</import>
        <import>tests.xml</import>
        <token name="@TOOL_VERSION@">1.26.4</token>
        <token name="@VERSION_SUFFIX@">2</token>
    </macros>
    <creator>
        <expand macro="creators/bmcv"/>
    </creator>
    <edam_operations>
        <edam_operation>operation_3443</edam_operation>
    </edam_operations>
    <requirements>
        <requirement type="package" version="@TOOL_VERSION@">numpy</requirement>
        <requirement type="package" version="0.22.0">scikit-image</requirement>
        <requirement type="package" version="0.1">giatools</requirement>
    </requirements>
    <command><![CDATA[
    
    ## Inputs
    
    python '$__tool_directory__/image_math.py'
    --expression='$expression'
    #for $item in $inputs:
        --input='$item.name:$item.image'
    #end for
    
    ## Outputs
    
    --output='./result.tiff'
    
    ]]>
    </command>
    <inputs>
        <param argument="--expression" type="text" label="Expression" optional="false">
            <validator type="regex">^[a-zA-Z0-9-_\*\+ \(\)/]+$</validator>
        </param>
        <repeat name="inputs" title="Input images" min="1">
            <param name="image" type="data" format="png,tiff" label="Image" />
            <param name="name" type="text" label="Variable for representation of the image within the expression" optional="false">
                <validator type="regex">^[a-zA-Z_][a-zA-Z0-9_]*$</validator>
            </param>
        </repeat>
    </inputs>
    <outputs>
       <data format="tiff" name="result" from_work_dir="result.tiff" />
    </outputs>
    <tests>
        <!-- Multiplication with a scalar -->
        <test>
            <param name="expression" value="input1 * 2" />
            <repeat name="inputs">
                <param name="image" value="input1.tiff" />
                <param name="name" value="input1" />
            </repeat>
            <expand macro="tests/intensity_image_diff" name="result" value="input1_times_2.tiff" ftype="tiff"/>
        </test>
        <!-- Unary negation operator -->
        <test>
            <param name="expression" value="-input1" />
            <repeat name="inputs">
                <param name="image" value="input1.tiff" />
                <param name="name" value="input1" />
            </repeat>
            <expand macro="tests/intensity_image_diff" name="result" value="minus_input1.tiff" ftype="tiff"/>
        </test>
        <!-- Binary addition, neutral element, addition with scalar -->
        <test>
            <param name="expression" value="input1 + input2 + 1" />
            <repeat name="inputs">
                <param name="image" value="input1.tiff" />
                <param name="name" value="input1" />
            </repeat>
            <repeat name="inputs">
                <param name="image" value="minus_input1.tiff" />
                <param name="name" value="input2" />
            </repeat>
            <expand macro="tests/intensity_image_diff" name="result" value="ones.tiff" ftype="tiff"/>
        </test>
        <!-- Parentheses -->
        <test>
            <param name="expression" value="(input1 + input2) / 2" />
            <repeat name="inputs">
                <param name="image" value="input1.tiff" />
                <param name="name" value="input1" />
            </repeat>
            <repeat name="inputs">
                <param name="image" value="ones.tiff" />
                <param name="name" value="input2" />
            </repeat>
            <expand macro="tests/intensity_image_diff" name="result" value="half_of_input1_plus_one.tiff" ftype="tiff"/>
        </test>
        <!-- Abs -->
        <test>
            <param name="expression" value="abs(input)" />
            <repeat name="inputs">
                <param name="image" value="input1.tiff" />
                <param name="name" value="input" />
            </repeat>
            <expand macro="tests/intensity_image_diff" name="result" value="input1_abs.tiff" ftype="tiff"/>
        </test>
    </tests>
    <help>

        **Processes images according to pixel-wise arithmetic expressions.**

        The supported pixel-wise expressions are:

        - Addition, subtraction, multiplication, and division (``+``, ``-``, ``*``, ``/``)
        - Integer division (e.g., ``input // 2``)
        - Power (e.g., ``input ** 2``)
        - Negation (e.g., ``-input``)
        - Absolute values (e.g., ``abs(input)``)
        - Square root (e.g., ``sqrt(input)``)
        - Combinations of the above (also using parentheses)

        Examples:

        - **Negate an image.**
          Expression: ``-image``
          where ``image`` is an arbitrary input image.

        - **Mean of two images.**
          Expression: ``(image1 + image2) / 2``
          where ``image1`` and `image2` are two arbitrary input images.

        - **Perform division avoiding division-by-zero.**
          Expression: ``image1 / (abs(image2) + 1e-8)``
          where ``image1`` and `image2` are two arbitrary input images.

    </help>
    <citations>
        <citation type="doi">10.1038/s41586-020-2649-2</citation>
    </citations>
</tool>