# This file was auto generated by Styx.
# Do not edit this file directly.

import typing
import pathlib
from styxdefs import *

TEXTURE_COOCCURRENCE_FEATURES_METADATA = Metadata(
    id="91591f77263330ed7a5bfa1c36e1edb089c3c166.boutiques",
    name="TextureCooccurrenceFeatures",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


TextureCooccurrenceFeaturesParameters = typing.TypedDict('TextureCooccurrenceFeaturesParameters', {
    "__STYX_TYPE__": typing.Literal["TextureCooccurrenceFeatures"],
    "image_dimension": int,
    "input_image": InputPathType,
    "number_of_bins_per_axis": typing.NotRequired[int | None],
    "mask_image": typing.NotRequired[InputPathType | None],
    "mask_label": typing.NotRequired[int | None],
})


def dyn_cargs(
    t: str,
) -> typing.Any:
    """
    Get build cargs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build cargs function.
    """
    return {
        "TextureCooccurrenceFeatures": texture_cooccurrence_features_cargs,
    }.get(t)


def dyn_outputs(
    t: str,
) -> typing.Any:
    """
    Get build outputs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build outputs function.
    """
    return {
        "TextureCooccurrenceFeatures": texture_cooccurrence_features_outputs,
    }.get(t)


class TextureCooccurrenceFeaturesOutputs(typing.NamedTuple):
    """
    Output object returned when calling `texture_cooccurrence_features(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    features_output: OutputPathType
    """The output file containing the calculated texture co-occurrence
    features."""


def texture_cooccurrence_features_params(
    image_dimension: int,
    input_image: InputPathType,
    number_of_bins_per_axis: int | None = 256,
    mask_image: InputPathType | None = None,
    mask_label: int | None = 1,
) -> TextureCooccurrenceFeaturesParameters:
    """
    Build parameters.
    
    Args:
        image_dimension: The dimensionality of the input image, e.g., 2 for 2D\
            images, 3 for 3D images.
        input_image: The input image file for which texture co-occurrence\
            features will be calculated.
        number_of_bins_per_axis: The number of bins per axis to be used in the\
            histogram for texture calculation. Defaults to 256.
        mask_image: Optional mask image to specify the regions of interest in\
            the input image for which features will be calculated.
        mask_label: Label value in the mask image to specify which region to\
            process. Defaults to 1.
    Returns:
        Parameter dictionary
    """
    params = {
        "__STYXTYPE__": "TextureCooccurrenceFeatures",
        "image_dimension": image_dimension,
        "input_image": input_image,
    }
    if number_of_bins_per_axis is not None:
        params["number_of_bins_per_axis"] = number_of_bins_per_axis
    if mask_image is not None:
        params["mask_image"] = mask_image
    if mask_label is not None:
        params["mask_label"] = mask_label
    return params


def texture_cooccurrence_features_cargs(
    params: TextureCooccurrenceFeaturesParameters,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("TextureCooccurrenceFeatures")
    cargs.append(str(params.get("image_dimension")))
    cargs.append(execution.input_file(params.get("input_image")))
    if params.get("number_of_bins_per_axis") is not None:
        cargs.append(str(params.get("number_of_bins_per_axis")))
    if params.get("mask_image") is not None:
        cargs.append(execution.input_file(params.get("mask_image")))
    if params.get("mask_label") is not None:
        cargs.append(str(params.get("mask_label")))
    return cargs


def texture_cooccurrence_features_outputs(
    params: TextureCooccurrenceFeaturesParameters,
    execution: Execution,
) -> TextureCooccurrenceFeaturesOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = TextureCooccurrenceFeaturesOutputs(
        root=execution.output_file("."),
        features_output=execution.output_file(pathlib.Path(params.get("input_image")).name + "_features.txt"),
    )
    return ret


def texture_cooccurrence_features_execute(
    params: TextureCooccurrenceFeaturesParameters,
    execution: Execution,
) -> TextureCooccurrenceFeaturesOutputs:
    """
    Calculates texture co-occurrence features such as Energy, Entropy, Inverse
    Difference Moment, Inertia, Cluster Shade, and Cluster Prominence from an input
    image.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        execution: The execution object.
    Returns:
        NamedTuple of outputs (described in `TextureCooccurrenceFeaturesOutputs`).
    """
    params = execution.params(params)
    cargs = texture_cooccurrence_features_cargs(params, execution)
    ret = texture_cooccurrence_features_outputs(params, execution)
    execution.run(cargs)
    return ret


def texture_cooccurrence_features(
    image_dimension: int,
    input_image: InputPathType,
    number_of_bins_per_axis: int | None = 256,
    mask_image: InputPathType | None = None,
    mask_label: int | None = 1,
    runner: Runner | None = None,
) -> TextureCooccurrenceFeaturesOutputs:
    """
    Calculates texture co-occurrence features such as Energy, Entropy, Inverse
    Difference Moment, Inertia, Cluster Shade, and Cluster Prominence from an input
    image.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        image_dimension: The dimensionality of the input image, e.g., 2 for 2D\
            images, 3 for 3D images.
        input_image: The input image file for which texture co-occurrence\
            features will be calculated.
        number_of_bins_per_axis: The number of bins per axis to be used in the\
            histogram for texture calculation. Defaults to 256.
        mask_image: Optional mask image to specify the regions of interest in\
            the input image for which features will be calculated.
        mask_label: Label value in the mask image to specify which region to\
            process. Defaults to 1.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `TextureCooccurrenceFeaturesOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(TEXTURE_COOCCURRENCE_FEATURES_METADATA)
    params = texture_cooccurrence_features_params(
        image_dimension=image_dimension,
        input_image=input_image,
        number_of_bins_per_axis=number_of_bins_per_axis,
        mask_image=mask_image,
        mask_label=mask_label,
    )
    return texture_cooccurrence_features_execute(params, execution)


__all__ = [
    "TEXTURE_COOCCURRENCE_FEATURES_METADATA",
    "TextureCooccurrenceFeaturesOutputs",
    "TextureCooccurrenceFeaturesParameters",
    "texture_cooccurrence_features",
    "texture_cooccurrence_features_params",
]
