view enhance_or_suppress_features.xml @ 3:169cde4adbdb draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit c3917e27eb1c1deeb381aa0dc8161c07699562fb"
author bgruening
date Mon, 11 May 2020 11:40:39 +0000
parents b7014aafa455
children dc9b6e9d717b
line wrap: on
line source

<tool id="cp_enhance_or_suppress_features" name="EnhanceOrSuppressFeatures" version="@CP_VERSION@">
    <description>to improve subsequent identification of objects</description>

    <macros>
        <import>macros.xml</import>

        <xml name="feature_speckles">
            <param name="speckles_feature_size" label="Feature size" type="integer" value="10" help="Enter the diameter of the largest speckle, the width of the circle, or the width of the neurites to be enhanced or suppressed, which will be used to calculate an appropriate filter size." />
            <param name="speed_accuracy" label="Speed and accuracy" type="select">
                <help>
                    <![CDATA[
                        Speckles can use a fast or slow algorithm to find speckles.
                        <br> - Fast: Select this option for speckles that have a large radius (greater than 10 pixels) and need not be exactly circular.
                        <br> - Slow: Use for speckles of small radius.
                        ]]>
                </help>
                <option value="Fast">Fast</option>
                <option value="Slow">Slow</option>
            </param>
        </xml>
        <xml name="feature_neurites">
            <conditional name="con_feature_neurites">
                <param name="enhancement_method" label="Enhancement method" type="select">
                    <help>
                        <![CDATA[
                            Two methods can be used to enhance neurites:
                            <br> - Tubeness: This method is an adaptation of the method used by the ImageJ Tubeness plugin. The image is smoothed with a Gaussian. The Hessian is then computed at every point to measure the intensity gradient and the eigenvalues of the Hessian are computed to determine the magnitude of the intensity. The absolute maximum of the two eigenvalues gives a measure of the ratio of the intensity of the gradient in the direction of its most rapid descent versus in the orthogonal direction. The output image is the absolute magnitude of the highest eigenvalue if that eigenvalue is negative (white neurite on dark background), otherwise, zero.
                            <br> - Line structures: The module takes the difference of the white and black tophat filters (a white tophat filtering is the image minus the morphological grayscale opening of the image; a black tophat filtering is the morphological grayscale closing of the image minus the image). The effect is to enhance lines whose width is the feature size.
                            ]]>
                    </help>
                    <option value="Tubeness">Tubeness</option>
                    <option value="Line structures">Line structures</option>
                </param>
                <when value="Tubeness">
                    <param name="tube_smoothing_scale" label="Smoothing scale" type="float" value="2.0" min="0.0" help="The Tubeness option uses this scale as the sigma of the Gaussian used to smooth the image prior to gradient detection." />
                </when>
                <when value="Line structures">
                    <param name="line_structures_feature_size" label="Feature size" type="integer" value="10" help="Enter the diameter of the largest speckle, the width of the circle, or the width of the neurites to be enhanced or suppressed, which will be used to calculate an appropriate filter size."/>
                </when>
            </conditional>
        </xml>
        <xml name="feature_darkholes">
            <param name="min_hole_size" label="Minimum hole size" type="integer" value="1" min="0"/>
            <param name="max_hole_size" label="Maximum hole size" type="integer" value="10" min="0"/>
        </xml>
        <xml name="feature_circle">
            <param name="circle_feature_size" label="Feature size" type="integer" value="10" help="Enter the diameter of the largest speckle, the width of the circle, or the width of the neurites to be enhanced or suppressed, which will be used to calculate an appropriate filter size."/>
        </xml>
        <xml name="feature_texture">
            <param name="texture_smoothing_scale" label="Smoothing scale" type="float" value="2.0" min="0.0" help="This is roughly the scale of the texture features, in pixels. The algorithm uses the smoothing value entered as the sigma of the Gaussian used to weight nearby pixels by distance in the variance calculation." />
        </xml>
        <xml name="feature_dic">
            <param name="dic_smoothing_scale" label="Smoothing scale" type="float" value="2.0" min="0.0" help="Specifies the amount of smoothing of the image in the direction parallel to the shear axis of the image. The line integration method will leave streaks in the image without smoothing as it encounters noisy pixels during the course of the integration. The smoothing takes contributions from nearby pixels, which decreases the noise but smooths the resulting image. Increase the smoothing to eliminate streakiness and decrease the smoothing to sharpen the image." />
            <param name="dic_shear_angle" label="Shear angle" type="float" value="0.0" min="0.0" help="The shear angle is the direction of constant value for the shadows and highlights in a DIC image. The gradients in a DIC image run in the direction perpendicular to the shear angle." />
            <param name="dic_decay" label="Decay" type="float" value="0.95" min="0.0" help="The decay setting applies an exponential decay during the process of integration by multiplying the accumulated sum by the decay at each step. This lets the integration recover from accumulated error during the course of the integration, but it also results in diminished intensities in the middle of large objects. Set the decay to a large value, on the order of 1 - 1/diameter of your objects if the intensities decrease toward the middle. Set the decay to a small value if there appears to be a bias in the integration direction." />
        </xml>
    </macros>

    <expand macro="py_requirements"/>
    <expand macro="cmd_modules" />

    <configfiles>
        <inputs name="inputs" />
        <configfile name="script_file">
import json
import sys
import os

FOURSPACES=@SPACES@

input_json_path = sys.argv[1]
input_pipeline= sys.argv[2]

params = json.load(open(input_json_path, "r"))

def writeesf():
    _str = "\nEnhanceOrSuppressFeatures:[module_num:%d|svn_version:\\'Unknown\\'|variable_revision_number:6|show_window:False|notes:\\x5B\\'Identify nucleoli\\', \\'PARAMS\\x3A Range of hole sizes\'\\x5D|batch_state:array(\\x5B\\x5D, dtype=uint8)|enabled:True|wants_pause:False]\n" % new_count
    _str += FOURSPACES + "Select the input image:%s\n" % params['input_image']
    _str += FOURSPACES + "Name the output image:%s\n" % params['name_output_image']

    operation = params['con_enhance_suppress']['select_operation']
    _str += FOURSPACES + "Select the operation:%s\n" % operation

    con_feature_type = params['con_enhance_suppress']['con_feature_type']

    if operation == "Suppress":
        _str += FOURSPACES + "Feature size:%s\n" % params['con_enhance_suppress']['feature_size']
        ## Below values are not used in this case, but required by CP pipeline file to be
        ## present as some sorts of "default" values
        _str += FOURSPACES + "Feature type:Speckles"
        _str += FOURSPACES + "Range of hole sizes:1,10"
        _str += FOURSPACES + "Smoothing scale:2.0"
        _str += FOURSPACES + "Shear angle:0.0"
        _str += FOURSPACES + "Decay:0.95"
        _str += FOURSPACES + "Enhancement method:Tubeness"
        _str += FOURSPACES + "Speed and accuracy:Fast"
    elif operation == "Enhance":
        feature_type = con_feature_type['feature_type']

        if feature_type == "Speckles":
            _str += FOURSPACES + "Feature size:%d\n" % con_feature_type['speckles_feature_size']
            _str += FOURSPACES + "Feature type:%s\n" % feature_type
            _str += FOURSPACES + "Range of hole sizes:1,10\n"
            _str += FOURSPACES + "Smoothing scale:2.0\n"
            _str += FOURSPACES + "Shear angle:0.0\n"
            _str += FOURSPACES + "Decay:0.95\n"
            _str += FOURSPACES + "Enhancement method:Tubeness\n"
            _str += FOURSPACES + "Speed and accuracy:%s\n" % con_feature_type['speed_accuracy']
        elif feature_type == "Neurites":
            enhancement_method = con_feature_type['con_feature_neurites']['enhancement_method']
            if enhancement_method == "Tubeness":
                _str += FOURSPACES + "Feature size:10\n"
                _str += FOURSPACES + "Feature type:%s\n" % feature_type
                _str += FOURSPACES + "Range of hole sizes:1,10\n"
                _str += FOURSPACES + "Smoothing scale:%.1f\n" % con_feature_type['con_feature_neurites']['tube_smoothing_scale']
                _str += FOURSPACES + "Shear angle:0.0\n"
                _str += FOURSPACES + "Decay:0.95\n"
                _str += FOURSPACES + "Enhancement method:%s\n" % enhancement_method
                _str += FOURSPACES + "Speed and accuracy:Fast\n"
            elif enhancement_method == "Line structures":
                _str += FOURSPACES + "Feature size:%s\n" % con_feature_type['con_feature_neurites']['line_structures_feature_size']
                _str += FOURSPACES + "Feature type:%s\n" % feature_type
                _str += FOURSPACES + "Range of hole sizes:1,10\n"
                _str += FOURSPACES + "Smoothing scale:2.0\n"
                _str += FOURSPACES + "Shear angle:0.0\n"
                _str += FOURSPACES + "Decay:0.9\n5"
                _str += FOURSPACES + "Enhancement method:%s\n" % enhancement_method
                _str += FOURSPACES + "Speed and accuracy:Fast\n"
        elif feature_type == "Dark holes":
            _str += FOURSPACES + "Feature size:10\n"
            _str += FOURSPACES + "Feature type:%s\n" % feature_type
            _str += FOURSPACES + "Range of hole sizes:%d,%d\n" %(con_feature_type['min_hole_size'],con_feature_type['max_hole_size'])
            _str += FOURSPACES + "Smoothing scale:2.0\n"
            _str += FOURSPACES + "Shear angle:0.0\n"
            _str += FOURSPACES + "Decay:0.95\n"
            _str += FOURSPACES + "Enhancement method:Tubeness\n"
            _str += FOURSPACES + "Speed and accuracy:Fast\n"
        elif feature_type == "Circles":
            _str += FOURSPACES + "Feature size:%d\n" % con_feature_type['circle_feature_size']
            _str += FOURSPACES + "Feature type:%s\n" % feature_type
            _str += FOURSPACES + "Range of hole sizes:1,10\n"
            _str += FOURSPACES + "Smoothing scale:2.0\n"
            _str += FOURSPACES + "Shear angle:0.0\n"
            _str += FOURSPACES + "Decay:0.95\n"
            _str += FOURSPACES + "Enhancement method:Tubeness\n"
            _str += FOURSPACES + "Speed and accuracy:Fast\n"
        elif feature_type == "Texture":
            _str += FOURSPACES + "Feature size:%d\n" % con_feature_type['circle_feature_size']
            _str += FOURSPACES + "Feature type:%s\n" % feature_type
            _str += FOURSPACES + "Range of hole sizes:1,10\n"
            _str += FOURSPACES + "Smoothing scale:%.1f\n" % con_feature_type['texture_smoothing_scale']
            _str += FOURSPACES + "Shear angle:0.0\n"
            _str += FOURSPACES + "Decay:0.95\n"
            _str += FOURSPACES + "Enhancement method:Tubeness\n"
            _str += FOURSPACES + "Speed and accuracy:Fast\n"
        elif feature_type == "DIC":
            _str += FOURSPACES + "Feature size:10\n"
            _str += FOURSPACES + "Feature type:%s\n" % feature_type
            _str += FOURSPACES + "Range of hole sizes:1,10\n"
            _str += FOURSPACES + "Smoothing scale:%.1f\n" % con_feature_type['texture_smoothing_scale']
            _str += FOURSPACES + "Shear angle:%.1f\n" % con_feature_type['dic_shear_angle']
            _str += FOURSPACES + "Decay:%.2f\n" % con_feature_type['dic_decay']
            _str += FOURSPACES + "Enhancement method:Tubeness\n"
            _str += FOURSPACES + "Speed and accuracy:Fast\n"

    return _str

with open(input_pipeline) as fin:
    lines = fin.readlines()

    k, v = lines[4].strip().split(':')

    module_count = int(v)
    new_count = module_count + 1
    lines[4] = k + ":%d\n" % new_count

    with open("output.cppipe", "w") as f:
        f.writelines(lines)
        f.write(writeesf())

f.close()
        </configfile>
    </configfiles>

    <inputs>
        <expand macro="input_pipeline_param"/>
        <param name="input_image" type="text" label="Enter the name of the input image" />
        <param name="name_output_image" type="text" label="Enter a name for the resulting image" />
        <conditional name="con_enhance_suppress">
            <param name="select_operation" label="Select the operation" type="select" help="Enhance produces an image whose intensity is largely composed of the features of interest and Supress produces an image with the features largely removed.">
                <option value="Enhance">Enhance</option>
                <option value="Suppress">Suppress</option>
            </param>
            <when value="Enhance">
                <conditional name="con_feature_type">
                    <param name="feature_type" type="select" label="Feature type">
                        <help>
                            <![CDATA[
                                - Speckles: A speckle is an area of enhanced intensity relative to its immediate neighborhood. This option enhances speckles using a white tophat filter, which is the image minus the morphological grayscale opening of the image. The opening operation first suppresses the speckles by applying a grayscale erosion to reduce everything within a given radius to the lowest value within that radius, then uses a grayscale dilation to restore objects larger than the radius to an approximation of their former shape. The white tophat filter enhances speckles by subtracting the effects of opening from the original image.
                                <br>- Neurites: Neurites are taken to be long, thin features of enhanced intensity. Choose this option to enhance the intensity of the neurites using the Line structures or Tubeness methods described in a later setting.
                                <br>- Dark holes: This option uses morphological reconstruction (the rolling-ball algorithm) to identify dark holes within brighter areas, or brighter ring shapes. The image is inverted so that the dark holes turn into bright peaks. The image is successively eroded and the eroded image is reconstructed at each step, resulting in an image that is missing the peaks. Finally, the reconstructed image is subtracted from the previous reconstructed image. This leaves circular bright spots with a radius equal to the number of iterations performed.
                                <br>- Circles: This option calculates the circular Hough transform of the image at the diameter given by the feature size. The Hough transform will have the highest intensity at points that are centered within a ring of high intensity pixels where the ring diameter is the feature size. You may want to use the EnhanceEdges module to find the edges of your circular object and then process the output by enhancing circles. You can use IdentifyPrimaryObjects to find the circle centers and then use these centers as seeds in IdentifySecondaryObjects to find whole, circular objects using a watershed.
                                <br>- Texture: This option produces an image whose intensity is the variance among nearby pixels. The method weights pixel contributions by distance using a Gaussian to calculate the weighting. You can use this method to separate foreground from background if the foreground is textured and the background is not.
                                <br>- DIC: This method recovers the optical density of a DIC image by integrating in a direction perpendicular to the shear direction of the image.
                                ]]>
                        </help>
                        <option value="Speckles">Speckles</option>
                        <option value="Neurites">Neurites</option>
                        <option value="Dark holes">Dark holes</option>
                        <option value="Circles">Circles</option>
                        <option value="Texture">Texture</option>
                        <option value="DIC">DIC</option>
                    </param>
                    <when value="Speckles">
                        <expand macro="feature_speckles" />
                    </when>
                    <when value="Neurites">
                        <expand macro="feature_neurites" />
                    </when>
                    <when value="Dark holes">
                        <expand macro="feature_darkholes" />
                    </when>
                    <when value="Circles">
                        <expand macro="feature_circle" />
                    </when>
                    <when value="Texture">
                        <expand macro="feature_texture" />
                    </when>
                    <when value="DIC">
                        <expand macro="feature_dic" />
                    </when>
                </conditional>
            </when>
            <when value="Suppress">
                <param name="feature_size" type="integer" label="Feature size" value="10" help="Enter the diameter of the largest speckle, the width of the circle, or the width of the neurites to be enhanced or suppressed, which will be used to calculate an appropriate filter size." />
            </when>
        </conditional>
    </inputs>

    <outputs>
        <expand macro="output_pipeline_param" />
    </outputs>

    <tests>
        <test>
            <expand macro="test_input_pipeline_param" />
            <param name="input_image" value="DNA" />
            <param name="name_output_image" value="DNAdarkholes" />
            <conditional name="con_enhance_suppress">
                <param name="select_operation" value="Enhance" />
                <conditional name="con_feature_type">
                    <param name="feature_type" value="Dark holes" />
                    <param name="min_hole_size" value="1" />
                    <param name="max_hole_size" value="15" />
                </conditional>
            </conditional>
            <expand macro="test_out_file" file="enhance_or_suppress_features.cppipe" />
        </test>
    </tests>

    <help>
        <![CDATA[
            .. class:: infomark

            **What it does**

            This tool enhances or suppresses the intensity of certain pixels relative to the rest of the image, by applying image processing filters to the image. It produces a grayscale image in which objects can be identified using an Identify module.

            @COMMON_HELP@
            ]]>
    </help>

    <expand macro="citations" />
</tool>