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

import typing
import pathlib
from styxdefs import *
import dataclasses

ANTS_JOINT_LABEL_FUSION_SH_METADATA = Metadata(
    id="247a29d0e6dd59cbbad0a89af0ca5b7e052f7e73.boutiques",
    name="antsJointLabelFusion.sh",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


class AntsJointLabelFusionShOutputs(typing.NamedTuple):
    """
    Output object returned when calling `ants_joint_label_fusion_sh(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    segmentation_output: OutputPathType | None
    """Output segmented image."""


def ants_joint_label_fusion_sh(
    target_image: str,
    mask_image: str,
    dimensionality: typing.Literal[2, 3] | None = None,
    output: str | None = None,
    atlas_image_mrf: str | None = None,
    atlas_segmentation_mrf: str | None = None,
    rigid_transform: str | None = None,
    similarity_metric: str | None = None,
    other_options: str | None = None,
    verbose: typing.Literal[0, 1] | None = None,
    rigid_transform_additional_options: str | None = None,
    similarity_metric_additional_options: str | None = None,
    runner: Runner | None = None,
) -> AntsJointLabelFusionShOutputs:
    """
    The antsJointLabelFusion script is used for performing label fusion using
    multiple atlases to improve segmentation accuracy.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        target_image: Image to segment.
        mask_image: Mask image.
        dimensionality: Image dimensionality (2 or 3).
        output: Root directory for the output segmentation.
        atlas_image_mrf: Atlas image(s) to be used for MRF initialization.
        atlas_segmentation_mrf: Atlas segmentation(s) to be used for MRF\
            initialization.
        rigid_transform: Rigid transform initialization.
        similarity_metric: Metric used for calculating similarity.
        other_options: Additional options for label fusion.
        verbose: Verbose output.
        rigid_transform_additional_options: Additional options for rigid\
            transform.
        similarity_metric_additional_options: Additional options for similarity\
            metric.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsJointLabelFusionShOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(ANTS_JOINT_LABEL_FUSION_SH_METADATA)
    cargs = []
    cargs.append("antsJointLabelFusion.sh")
    if dimensionality is not None:
        cargs.extend([
            "-d",
            str(dimensionality)
        ])
    if output is not None:
        cargs.extend([
            "-o",
            output
        ])
    if atlas_image_mrf is not None:
        cargs.extend([
            "-a",
            atlas_image_mrf
        ])
    if atlas_segmentation_mrf is not None:
        cargs.extend([
            "-l",
            atlas_segmentation_mrf
        ])
    if rigid_transform is not None:
        cargs.extend([
            "-g",
            rigid_transform
        ])
    if similarity_metric is not None:
        cargs.extend([
            "-s",
            similarity_metric
        ])
    if other_options is not None:
        cargs.extend([
            "-k",
            other_options
        ])
    if verbose is not None:
        cargs.extend([
            "-v",
            str(verbose)
        ])
    cargs.extend([
        "-i",
        target_image
    ])
    cargs.extend([
        "-m",
        mask_image
    ])
    if rigid_transform_additional_options is not None:
        cargs.extend([
            "-g",
            rigid_transform_additional_options
        ])
    if similarity_metric_additional_options is not None:
        cargs.extend([
            "-x",
            similarity_metric_additional_options
        ])
    ret = AntsJointLabelFusionShOutputs(
        root=execution.output_file("."),
        segmentation_output=execution.output_file(output + ".nii.gz") if (output is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "ANTS_JOINT_LABEL_FUSION_SH_METADATA",
    "AntsJointLabelFusionShOutputs",
    "ants_joint_label_fusion_sh",
]
