view 2d_feature_extraction.xml @ 7:048545339ced draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/2d_feature_extraction/ commit b8e0b656d417db6e2ad0f187fc3c5afff0c3acd7
author imgteam
date Tue, 06 Jan 2026 09:25:17 +0000
parents 8e3a52b74876
children
line wrap: on
line source

<tool id="ip_2d_feature_extraction" name="Extract image features" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.05">
    <description>with scikit-image</description>
    <macros>
        <import>creators.xml</import>
        <import>validators.xml</import>
        <token name="@TOOL_VERSION@">0.25.2</token>
        <token name="@VERSION_SUFFIX@">1</token>
        <xml name="features">
            <param name="features" type="select" label="Available features" multiple="true" display="checkboxes"
                   help="*) Features marked with an asterisk are only available for 2-D images (not for 3-D images).">
                <option value="label" selected="true">Label from the label map</option>
                <yield/>
                <option value="area">Area</option>
                <option value="area_convex">Convex area</option>
                <option value="area_filled">Filled area</option>
                <option value="axis_major_length">Major axis length</option>
                <option value="axis_minor_length">Minor axis length</option>
                <option value="bbox">Bounding box</option>
                <option value="centroid">Centroid</option>
                <option value="eccentricity">Eccentricity*</option>
                <option value="equivalent_diameter_area">Equivalent diameter</option>
                <option value="euler_number">Euler number</option>
                <option value="extent">Extent</option>
                <option value="inertia_tensor_eigvals">Inertia tensor eigenvalues</option>
                <option value="moments">Moments</option>
                <option value="moments_hu">Moments Hu*</option>
                <option value="orientation">Orientation*</option>
                <option value="perimeter">Perimeter</option>
                <option value="solidity">Solidity</option>
            </param>
        </xml>
        <xml name="zarr-isolated-feature-test" tokens="feature">
            <test>
                <param name="labels" value="input/input13.zarr"/>
                <conditional name="setup">
                    <param name="mode" value="with-intensities"/>
                    <param name="intensities" value="input/input1_uint8.tiff"/>
                    <param name="features" value="@FEATURE@"/>
                </conditional>
                <output name="output" ftype="tabular" value="output/input13-@FEATURE@.tsv" compare="re_match"/>
            </test>
        </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">scikit-image</xref>
        <xref type="bio.tools">giatools</xref>
        <xref type="bio.tools">galaxy_image_analysis</xref>
        <xref type="biii">scikit-image</xref>
    </xrefs>
    <requirements>
        <requirement type="package" version="@TOOL_VERSION@">scikit-image</requirement>
        <requirement type="package" version="2.2.2">pandas</requirement>
        <requirement type="package" version="0.7.3">giatools</requirement>
        <requirement type="package" version="0.12.2">ome-zarr</requirement>
    </requirements>
    <required_files>
        <include type="literal" path="2d_feature_extraction.py"/>
    </required_files>
    <command detect_errors="aggressive"><![CDATA[

        python '$__tool_directory__/2d_feature_extraction.py'

        #if $labels.extension == "zarr"
            --labels '$labels.extra_files_path/$labels.metadata.store_root'
        #else
            --labels '$labels'
        #end if

        #if $setup.mode == "with-intensities"
            #if $setup.intensities.extension == "zarr"
                --intensities '$setup.intensities.extra_files_path/$setup.intensities.metadata.store_root'
            #else
                --intensities '$setup.intensities'
            #end if
        #end if

        --output '$output'
        --params '$params'
        --verbose

    ]]></command>
    <configfiles>
        <configfile name="params"><![CDATA[
            {
                "features": [
                    ${ ', '.join('"%s"' % t.strip() for t in str( $setup['features'] ).split(',')) }
                ]
            }
        ]]></configfile>
    </configfiles>
    <inputs>
        <param name="labels" type="data" format="tiff,zarr,png" label="Label map">
            <expand macro="validators/is_single_channel"/>
            <expand macro="validators/is_single_frame"/>
        </param>
        <conditional name="setup">
            <param label="Features to compute" name="mode" type="select">
                <option value="without-intensities" selected="true">Only use the label map for feature extraction (no intensity-based features)</option>
                <option value="with-intensities">Use the intensity image to compute additional features</option>
            </param>
            <when value="without-intensities">
                <expand macro="features"/>
            </when>
            <when value="with-intensities">
                <param name="intensities" type="data" format="tiff,zarr,png,jpg" label="Intensity image">
                    <expand macro="validators/is_single_channel"/>
                    <expand macro="validators/is_single_frame"/>
                </param>
                <expand macro="features">
                    <option value="max_intensity">Maximum intensity</option>
                    <option value="mean_intensity">Mean intensity</option>
                    <option value="min_intensity">Minimum intensity</option>
                </expand>
            </when>
        </conditional>
    </inputs>
    <outputs>
        <data format="tabular" name="output"/>
    </outputs>
    <tests>
        <!-- Single-channel 2-D -->
        <test>
            <param name="labels" value="input/input12.png"/>
            <conditional name="setup">
                <param name="mode" value="without-intensities"/>
                <param name="features" value="label,area,area_convex,solidity"/>
            </conditional>
            <output name="output" ftype="tabular" value="output/input12.tsv" compare="re_match"/>
        </test>
        <test>
            <param name="labels" value="input/input11.tiff"/>
            <conditional name="setup">
                <param name="mode" value="with-intensities"/>
                <param name="intensities" value="input/input1_uint8.tiff"/>
                <param name="features" value="area,mean_intensity,perimeter"/>
            </conditional>
            <output name="output" ftype="tabular" value="output/input11.tsv" compare="re_match"/>
        </test>
        <!-- Single-channel 2-D Zarr (isolated features, verify that Dask arrays are converted to NumPy arrays whenever necessary) -->
        <expand macro="zarr-isolated-feature-test" feature="area"/>
        <expand macro="zarr-isolated-feature-test" feature="area_convex"/>
        <expand macro="zarr-isolated-feature-test" feature="area_filled"/>
        <expand macro="zarr-isolated-feature-test" feature="axis_major_length"/>
        <expand macro="zarr-isolated-feature-test" feature="axis_minor_length"/>
        <expand macro="zarr-isolated-feature-test" feature="bbox"/>
        <expand macro="zarr-isolated-feature-test" feature="centroid"/>
        <expand macro="zarr-isolated-feature-test" feature="eccentricity"/>
        <expand macro="zarr-isolated-feature-test" feature="equivalent_diameter_area"/>
        <expand macro="zarr-isolated-feature-test" feature="euler_number"/>
        <expand macro="zarr-isolated-feature-test" feature="extent"/>
        <expand macro="zarr-isolated-feature-test" feature="inertia_tensor_eigvals"/>
        <expand macro="zarr-isolated-feature-test" feature="moments"/>
        <expand macro="zarr-isolated-feature-test" feature="moments_hu"/>
        <expand macro="zarr-isolated-feature-test" feature="orientation"/>
        <expand macro="zarr-isolated-feature-test" feature="perimeter"/>
        <expand macro="zarr-isolated-feature-test" feature="solidity"/>
        <expand macro="zarr-isolated-feature-test" feature="max_intensity"/>
        <expand macro="zarr-isolated-feature-test" feature="mean_intensity"/>
        <expand macro="zarr-isolated-feature-test" feature="min_intensity"/>
        <!-- Single-channel 3-D, test all features are supported in 3-D -->
        <test>
            <param name="labels" value="input/input9.zarr"/>
            <conditional name="setup">
                <param name="mode" value="with-intensities"/>
                <param name="intensities" value="input/input8_zyx.zarr"/>
                <param name="features" value="area,area_convex,area_filled,axis_major_length,axis_minor_length,bbox,centroid,eccentricity,equivalent_diameter_area,euler_number,extent,inertia_tensor_eigvals,moments,moments_hu,orientation,perimeter,solidity,max_intensity,mean_intensity,min_intensity"/>
            </conditional>
            <output name="output" ftype="tabular" value="output/input9.tsv" compare="re_match"/>
            <assert_stdout>
                <has_line line='Skip feature that is not available for 3-D images: "eccentricity"'/>
                <has_line line='Skip feature that is not available for 3-D images: "moments_hu"'/>
                <has_line line='Skip feature that is not available for 3-D images: "orientation"'/>
            </assert_stdout>
        </test>
        <!-- Multi-channel (forbidden) -->
        <test expect_failure="true">
            <param name="labels" value="input/input12.png"/>
            <conditional name="setup">
                <param name="mode" value="with-intensities"/>
                <param name="intensities" value="input/input3_uint16.tiff"/>
                <param name="features" value="label"/>
            </conditional>
            <assert_stderr>
                <!-- Rejected by validator -->
                <has_n_lines n="0"/>
            </assert_stderr>
            <assert_stdout>
                <!-- Rejected by validator -->
                <has_n_lines n="0"/>
            </assert_stdout>
        </test>
        <test expect_failure="true">
            <param name="labels" value="input/input10.zarr"/>
            <conditional name="setup">
                <param name="mode" value="without-intensities"/>
                <param name="features" value="label"/>
            </conditional>
            <assert_stderr>
                <!-- Rejected by py-script -->
                <has_text text="This tool is not applicable to images with CYX axes."/>
            </assert_stderr>
        </test>
    </tests>
    <help>

**Computes features of a label map.**

The computed features are computed based solely on the properties of the objects in the label map, or, optionally, by also taking the intensities from a corresponding intensity image into account. Labels with value 0 are ignored.

Both images must be 2-D or 3-D single-channel images.

Supported Features
==================

**Area:** Area of the region i.e. number of pixels of the region scaled by pixel-area.

**Convex area:** Area of the convex hull image, which is the smallest convex polygon that encloses the region.

**Filled area:** Area of the region with all the holes filled in.

**Major axis length:** The length of the major axis of the ellipse that has the same normalized second central moments as the region.

**Minor axis length:** The length of the minor axis of the ellipse that has the same normalized second central moments as the region.

**Bounding box:** Bounding box `(min_row, min_col, max_row, max_col)`. Pixels belonging to the bounding box are in the half-open interval `[min_row; max_row)` and `[min_col; max_col)`.

**Centroid:** Centroid coordinates in separate columns ``centroid_x``, ``centroid_y``, and ``centroid_z`` when processing 3-D data.

**Eccentricity:** Eccentricity of the ellipse that has the same second-moments as the region. The eccentricity is the ratio of the focal distance (distance between focal points) over the major axis length. The value is in the interval [0, 1). When it is 0, the ellipse becomes a circle.

**Equivalent diameter:** The diameter of a circle with the same area as the region.

**Euler number:** Euler characteristic of the set of non-zero pixels. Computed as number of connected components subtracted by number of holes (input.ndim connectivity). In 3-D, number of connected components plus number of holes subtracted by number of tunnels.

**Extent:** Ratio of pixels in the region to pixels in the total bounding box. Computed as `area / (rows * cols)`.

**Inertia tensor eigenvalues:** The eigenvalues of the inertia tensor in decreasing order.

**Moments:** Spatial moments up to 3rd order: `m_ij = sum{ array(row, col) * row^i * col^j }` where the sum is over the row, col coordinates of the region.

**Moments Hu:** Hu moments (translation, scale and rotation invariant).

**Orientation:** Angle between the vertical axis (rows) and the major axis of the ellipse that has the same second moments as the region, ranging from `-pi/2` to `pi/2` counter-clockwise.

**Perimeter:** Perimeter of object which approximates the contour as a line through the centers of border pixels using a 4-connectivity. Generalizes to the surface of an object in 3-D, which uses a different approximation.

**Solidity:** Ratio of pixels in the region to pixels of the convex hull image.
    
    </help>
    <citations>
        <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation>
    </citations>
</tool>