view image_math.xml @ 0:2005f8058036 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 1907942bef43b20edfdbd1d1b5eb1cac3602848b"
author bgruening
date Thu, 16 Apr 2020 05:33:39 -0400
parents
children 6d3851ac885f
line wrap: on
line source

<tool id="cp_image_math" name="ImageMath" version="0.1.0" python_template_version="3.5">
    <description>perform simple mathematical operations on images</description>
    <macros>
        <import>macros.xml</import>

        <xml name="image_without_multiplier" token_order="first">
            <conditional name="image_or_measurement_@ORDER@">
                <param name="image_or_measurement_@ORDER@" type="select" label="Image or measurement?" help="You can perform math operations or you can use a measurement for one of the operands.">
                    <option value="Image">Image</option>
                    <option value="Measurement">Measurement</option>
                </param>
                <when value="Image">
                    <param name="select_the_@ORDER@_image" type="text" label="Enter the name of the @ORDER@ image">
                        <expand macro="text_validator"/>
                    </param>
                </when>
                <when value="Measurement">
                    <conditional name="category_@ORDER@">
                        <param name="category_@ORDER@" type="select" label="Category" help="Select a measurement made on the @ORDER@ image. The value of the measurement is used for the operand for all of the pixels of the other operand's image.">
                            <option value="FileName">FileName</option>
                            <option value="Frame">Frame</option>
                            <option value="Height">Height</option>
                            <option value="MD5digest">MD5Digest</option>
                            <option value="PathName">PathName</option>
                            <option value="Scaling">Scaling</option>
                            <option value="Series">Series</option>
                            <option value="URL">URL</option>
                            <option value="Width">Width</option>
                        </param>
                        <when value="FileName">
                            <param name="measurement_@ORDER@" type="text" label="Measurement">
                                <expand macro="text_validator"/>
                            </param>
                        </when>
                        <when value="Frame">
                            <param name="measurement_@ORDER@" type="text" label="Measurement">
                                <expand macro="text_validator"/>
                            </param>
                        </when>
                        <when value="Height">
                            <param name="measurement_@ORDER@" type="text" label="Measurement">
                                <expand macro="text_validator"/>
                            </param>
                        </when>
                        <when value="MD5digest">
                            <param name="measurement_@ORDER@" type="text" label="Measurement">
                                <expand macro="text_validator"/>
                            </param>
                        </when>
                        <when value="PathName">
                            <param name="measurement_@ORDER@" type="text" label="Measurement">
                                <expand macro="text_validator"/>
                            </param>
                        </when>
                        <when value="Scaling">
                            <param name="measurement_@ORDER@" type="text" label="Measurement">
                                <expand macro="text_validator"/>
                            </param>
                        </when>
                        <when value="Series">
                            <param name="measurement_@ORDER@" type="text" label="Measurement">
                                <expand macro="text_validator"/>
                            </param>
                        </when>
                        <when value="URL">
                            <param name="measurement_@ORDER@" type="text" label="Measurement">
                                <expand macro="text_validator"/>
                            </param>
                        </when>
                        <when value="Width">
                            <param name="measurement_@ORDER@" type="text" label="Measurement">
                                <expand macro="text_validator"/>
                            </param>
                        </when>
                    </conditional>
                </when>
            </conditional>
        </xml>


        <xml name="section_image_with_multiplier" token_title="First Image" token_order="first">
            <section name="@ORDER@_image" title="@TITLE@" expanded="true">
                <expand macro="image_without_multiplier" order="@ORDER@"/>
                <param name="multiply_the_@ORDER@_image_by" type="float" value="1.0" label="Enter the number that you would like to multiply the @ORDER@ image by"/>
            </section>
        </xml>


        <xml name="section_image_without_multiplier" token_title="First Image" token_order="first">
            <section name="@ORDER@_image" title="@TITLE@" expanded="true">
                <expand macro="image_without_multiplier" order="@ORDER@"/>
            </section>
        </xml>


        <xml name="section_ops_result">
            <section name="op_results" title="OPERATIONS ON THE RESULTS" expanded="false">
                <param name="raise_the_power_of_the_result_by" type="float" value="1.0" label="Enter an exponent to raise the result to after the chosen operation"/>
                <param name="multiply_the_result_by" type="float" value="1.0" label="Enter the number that you would like to multiply the above image by"/>
                <param name="add_to_result" type="float" value="0.0" label="Enter a number to add to the result after the chosen operation"/>
                <param name="set_values_less_than_0_equal_to_0" type="select" display="radio" label="Set the values less than 0 equal to 0?" help="Values outside the range 0 to 1 might not be handled well by other CellProfiler tools.">
                    <option value="Yes">Yes</option>
                    <option value="No">No</option>
                </param>
                <param name="set_values_greater_than_1_equal_to_1" type="select" display="radio" label="Set the values greater than 1 equal to 1?" help="Values outside the range 0 to 1 might not be handled well by other CellProfiler tools.">
                    <option value="Yes">Yes</option>
                    <option value="No">No</option>
                </param>
            </section>
        </xml>
    </macros>
    <expand macro="py_requirements"/>
    <command detect_errors="exit_code">
        <![CDATA[
            python '$__tool_directory__/image_math.py' -p '$input_pipeline' -i '$input_json'
            ]]>
    </command>
    <configfiles>
        <inputs name="input_json"/>
    </configfiles>
    <inputs>
        <expand macro="input_pipeline_macro"/>
        <param name="name_output_image" type="text" label="Enter a name for the resulting image">
            <expand macro="text_validator"/>
        </param>
        <conditional name="operation">
            <param name="operation" type="select" label="Operation" help="You can select operations for single images (Invert, Log transform base 2, Log transform legacy) or between pairs of images (Add, Subtract, Absolute Difference, Multiply, Divide, Average, Minimum, Maximum). Some operations produce binary images (And, Or, Not, Equals).">
                <option value="add">Add</option>
                <option value="subtract">Subtract</option>
                <option value="multiply">Multiply</option>
                <option value="divide">Divide</option>
                <option value="average">Average</option>
                <option value="minimum">Minimum</option>
                <option value="maximum">Maximum</option>
                <option value="invert">Invert</option>
                <option value="log_2">Log transform (base 2)</option>
                <option value="log_legacy">Log transform (legacy)</option>
                <option value="and">And</option>
                <option value="or">Or</option>
                <option value="not">Not</option>
                <option value="equals">Equals</option>
            </param>
            <when value="add">
                <expand macro="section_image_with_multiplier" title="First Image" order="first"/>
                <expand macro="section_image_with_multiplier" title="Second Image" order="second"/>
                <expand macro="section_ops_result"/>
            </when>
            <when value="subtract">
                <expand macro="section_image_with_multiplier" title="First Image" order="first"/>
                <expand macro="section_image_with_multiplier" title="Second Image" order="second"/>
                <expand macro="section_ops_result"/>
            </when>
            <when value="multiply">
                <expand macro="section_image_with_multiplier" title="First Image" order="first"/>
                <expand macro="section_image_with_multiplier" title="Second Image" order="second"/>
                <expand macro="section_ops_result"/>
            </when>
            <when value="divide">
                <expand macro="section_image_with_multiplier" title="First Image" order="first"/>
                <expand macro="section_image_with_multiplier" title="Second Image" order="second"/>
                <expand macro="section_ops_result"/>
            </when>
            <when value="average">
                <expand macro="section_image_with_multiplier" title="First Image" order="first"/>
                <expand macro="section_image_with_multiplier" title="Second Image" order="second"/>
                <expand macro="section_ops_result"/>
            </when>
            <when value="minimum">
                <expand macro="section_image_with_multiplier" title="First Image" order="first"/>
                <expand macro="section_image_with_multiplier" title="Second Image" order="second"/>
                <expand macro="section_ops_result"/>
            </when>
            <when value="maximum">
                <expand macro="section_image_with_multiplier" title="First Image" order="first"/>
                <expand macro="section_image_with_multiplier" title="Second Image" order="second"/>
                <expand macro="section_ops_result"/>
            </when>
            <when value="invert">
                <param name="select_the_image" type="text" label="Select the image">
                    <expand macro="text_validator"/>
                </param>
                <param name="multiply_the_image_by" type="float" value="1.0" label="Enter the number that you would like to multiply the above image by"/>
                <expand macro="section_ops_result"/>
            </when>
            <when value="log_2">
                <param name="select_the_image" type="text" label="Select the image">
                    <expand macro="text_validator"/>
                </param>
                <param name="multiply_the_image_by" type="float" value="1.0" label="Enter the number that you would like to multiply the above image by"/>
                <expand macro="section_ops_result"/>
            </when>
            <when value="log_legacy">
                <param name="select_the_image" type="text" label="Select the image">
                    <expand macro="text_validator"/>
                </param>
                <param name="multiply_the_image_by" type="float" value="1.0" label="Enter the number that you would like to multiply the above image by"/>
                <expand macro="section_ops_result"/>
            </when>
            <when value="and">
                <expand macro="section_image_without_multiplier" title="First Image" order="first"/>
                <expand macro="section_image_without_multiplier" title="Second Image" order="second"/>
            </when>
            <when value="or">
                <expand macro="section_image_without_multiplier" title="First Image" order="first"/>
                <expand macro="section_image_without_multiplier" title="Second Image" order="second"/>
            </when>
            <when value="not">
                <section name="first_image" title="Image" expanded="true">
                    <conditional name="image_or_measurement_first">
                        <param name="image_or_measurement_first" type="select" label="Image or measurement?">
                            <option value="Image">Image</option>
                        </param>
                        <when value="Image">
                            <param name="select_the_first_image" type="text" label="Enter the name of the image">
                                <expand macro="text_validator"/>
                            </param>
                        </when>
                    </conditional>
                </section>
            </when>
            <when value="equals">
                <expand macro="section_image_without_multiplier" title="First Image" order="first"/>
                <expand macro="section_image_without_multiplier" title="Second Image" order="second"/>
            </when>
        </conditional>
        <param name="ignore_the_image_masks" type="select" display="radio" label="Ignore the image masks?" help="Select Yes to set equal to zero all previously masked pixels and operate on the masked images as if no mask had been applied. Otherwise, the smallest image mask is applied after image math has been completed.">
            <option value="Yes">Yes</option>
            <option value="No">No</option>
        </param>
    </inputs>
    <outputs>
        <data name="output_pipeline" from_work_dir="output.cppipe" format="txt"/>
    </outputs>
    <tests>
        <test>
            <param name="input_pipeline" value="common_image_math.cppipe"/>
            <param name="operation" value="add"/>
            <param name="raise_the_power_of_the_result_by" value="1.0"/>
            <param name="multiply_the_result_by" value="1.0"/>
            <param name="add_to_result" value="0.0"/>
            <param name="set_values_less_than_0_equal_to_0" value="Yes"/>
            <param name="set_values_greater_than_1_equal_to_1" value="Yes"/>
            <param name="ignore_the_image_masks" value="No"/>
            <param name="name_output_image" value="ImageAfterMath"/>
            <param name="image_or_measurement_first" value="Image"/>
            <param name="select_the_first_image" value="DNA"/>
            <param name="multiply_the_first_image_by" value="1.0"/>
            <param name="image_or_measurement_second" value="Image"/>
            <param name="select_the_second_image" value="CellImage"/>
            <param name="multiply_the_second_image_by" value="2.0"/>
            <output name="output_pipeline" ftype="txt" file="image_math_1.cppipe" lines_diff="0"/>
        </test>
        <test>
            <param name="input_pipeline" value="common_image_math.cppipe"/>
            <param name="operation" value="subtract"/>
            <param name="raise_the_power_of_the_result_by" value="1.0"/>
            <param name="multiply_the_result_by" value="1.0"/>
            <param name="add_to_result" value="0.0"/>
            <param name="set_values_less_than_0_equal_to_0" value="Yes"/>
            <param name="set_values_greater_than_1_equal_to_1" value="No"/>
            <param name="ignore_the_image_masks" value="No"/>
            <param name="name_output_image" value="ImageAfterMath"/>
            <param name="image_or_measurement_first" value="Image"/>
            <param name="select_the_first_image" value="DNA"/>
            <param name="multiply_the_first_image_by" value="1.0"/>
            <param name="image_or_measurement_second" value="Measurement"/>
            <param name="multiply_the_second_image_by" value="5.0"/>
            <param name="category_second" value="FileName"/>
            <param name="measurement_second" value="DNA"/>
            <output name="output_pipeline" ftype="txt" file="image_math_2.cppipe" lines_diff="0"/>
        </test>
        <test>
            <param name="input_pipeline" value="common_image_math.cppipe"/>
            <param name="operation" value="not"/>
            <param name="name_output_image" value="ImageAfterMath"/>
            <param name="select_the_first_image" value="DNA"/>
            <param name="ignore_the_image_masks" value="No"/>
            <output name="output_pipeline" ftype="txt" file="image_math_3.cppipe" lines_diff="0"/>
        </test>
    </tests>
    <help>
        <![CDATA[

            .. class:: infomark

            **What it does**

            This module can perform addition, subtraction, multiplication, division, or averaging of two or more image intensities, as well as inversion, log transform, or scaling by a constant for individual image intensities.

            Keep in mind that after the requested operations are carried out, the final image may have a substantially different range of pixel intensities than the original. CellProfiler assumes that the image is scaled from 0 – 1 for object identification and display purposes, so additional rescaling may be needed. Please see the RescaleIntensity module for more scaling options.

            @COMMON_HELP@
            ]]>
    </help>
    <expand macro="citations"/>
</tool>