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

import typing
import pathlib
from styxdefs import *
import dataclasses

IMAGE_SET_STATISTICS_METADATA = Metadata(
    id="9329b484e2f67dba69c548b9b9a373ea2a072aa8.boutiques",
    name="ImageSetStatistics",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


class ImageSetStatisticsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `image_set_statistics(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    computed_statistics_image: OutputPathType
    """The output image containing the computed statistics."""


def image_set_statistics(
    image_dimension: int,
    controls_list: InputPathType,
    output_image: str,
    which_stat: typing.Literal[0, 1, 2, 3, 4, 5, 6, 7],
    roi: InputPathType | None = None,
    imagelist2: InputPathType | None = None,
    runner: Runner | None = None,
) -> ImageSetStatisticsOutputs:
    """
    ImageSetStatistics computes statistics from a set of images. The whichstat
    option defines the type of statistic to compute, ranging from median to
    similarity-weighted metrics.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        image_dimension: The dimensionality of the images to be processed by\
            ImageSetStatistics.
        controls_list: Text file containing the list of control images.
        output_image: The output image file where the computed statistics are\
            stored.
        which_stat: Choice of statistic to compute: 0 for median, 1 for max\
            probability appearance, 2 for weighted mean appearance, 3 for trimmed\
            mean, 4 for max value, 5 for similarity-weighted (requires imagelist2),\
            6 for best local match label, 7 for max value from ROI.
        roi: Region of interest image file, optional depending on the whichstat\
            option.
        imagelist2: List of similarity images used for similarity-weighted\
            statistics. Required if whichstat equals 5 or 6.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ImageSetStatisticsOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(IMAGE_SET_STATISTICS_METADATA)
    cargs = []
    cargs.append("ImageSetStatistics")
    cargs.append(str(image_dimension))
    cargs.extend([
        "[CONTROLS_LIST]",
        execution.input_file(controls_list)
    ])
    cargs.extend([
        "[OUTPUT_IMAGE]",
        output_image
    ])
    cargs.extend([
        "[WHICH_STAT]",
        str(which_stat)
    ])
    if roi is not None:
        cargs.extend([
            "[ROI]",
            execution.input_file(roi)
        ])
    if imagelist2 is not None:
        cargs.extend([
            "[IMAGELIST2]",
            execution.input_file(imagelist2)
        ])
    ret = ImageSetStatisticsOutputs(
        root=execution.output_file("."),
        computed_statistics_image=execution.output_file(output_image),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "IMAGE_SET_STATISTICS_METADATA",
    "ImageSetStatisticsOutputs",
    "image_set_statistics",
]
