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

import typing
import pathlib
from styxdefs import *
import dataclasses

THRESHOLD_IMAGE_METADATA = Metadata(
    id="21280b87f93b4982f5b7173d35c9223a6b16962d.boutiques",
    name="ThresholdImage",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


class ThresholdImageOutputs(typing.NamedTuple):
    """
    Output object returned when calling `threshold_image(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_image: OutputPathType
    """The resulting image after thresholding."""


def threshold_image(
    image_dimension: int,
    image_in: InputPathType,
    out_image: InputPathType,
    threshlo: float | None = None,
    threshhi: float | None = None,
    inside_value: float | None = None,
    outside_value: float | None = None,
    otsu_number_of_thresholds: float | None = None,
    kmeans_number_of_thresholds: float | None = None,
    mask_image: InputPathType | None = None,
    runner: Runner | None = None,
) -> ThresholdImageOutputs:
    """
    Image thresholding utility that applies different thresholding techniques to an
    input image. It can use fixed thresholds, Otsu method, or K-means for
    thresholding.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        image_dimension: The dimension of the input image.
        image_in: The input image file to be thresholded.
        out_image: The output image file after thresholding.
        threshlo: The lower threshold value for fixed thresholding.
        threshhi: The upper threshold value for fixed thresholding.
        inside_value: The pixel value to be used inside the threshold range.
        outside_value: The pixel value to be used outside the threshold range.
        otsu_number_of_thresholds: Number of thresholds to use when applying\
            the Otsu method.
        kmeans_number_of_thresholds: Number of thresholds to use when applying\
            the K-means method.
        mask_image: Optional mask image for the thresholding operation.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ThresholdImageOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(THRESHOLD_IMAGE_METADATA)
    cargs = []
    cargs.append("ThresholdImage")
    cargs.append(str(image_dimension))
    cargs.append(execution.input_file(image_in))
    cargs.append(execution.input_file(out_image))
    if threshlo is not None:
        cargs.append(str(threshlo))
    if threshhi is not None:
        cargs.append(str(threshhi))
    if inside_value is not None:
        cargs.append(str(inside_value))
    if outside_value is not None:
        cargs.append(str(outside_value))
    if otsu_number_of_thresholds is not None:
        cargs.append(str(otsu_number_of_thresholds))
    if kmeans_number_of_thresholds is not None:
        cargs.append(str(kmeans_number_of_thresholds))
    if mask_image is not None:
        cargs.append(execution.input_file(mask_image))
    ret = ThresholdImageOutputs(
        root=execution.output_file("."),
        output_image=execution.output_file(pathlib.Path(out_image).name),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "THRESHOLD_IMAGE_METADATA",
    "ThresholdImageOutputs",
    "threshold_image",
]
