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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_MORPHOLOGY_METADATA = Metadata(
    id="f01b6fc71ec054526271073daced052e1a34a01b.boutiques",
    name="mri_morphology",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriMorphologyOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_morphology(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_file: OutputPathType
    """The result of the morphological operation applied to the input volume."""


def mri_morphology(
    input_volume: InputPathType,
    operation: typing.Literal["open", "close", "dilate", "erode", "mode", "fill_holes", "erode_bottom", "dilate_thresh", "erode_thresh"],
    number_iter: int,
    output_volume: InputPathType,
    label_option: float | None = None,
    runner: Runner | None = None,
) -> MriMorphologyOutputs:
    """
    MRI Morphology Tool - performs various morphological operations on a volume.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        input_volume: Input volume file on which operations are to be applied.
        operation: Morphological operation to be performed. Options include:\
            open, close, dilate, erode, mode, fill_holes, erode_bottom,\
            dilate_thresh, erode_thresh.
        number_iter: Number of iterations to apply the operation.
        output_volume: Output volume file to store the results of the\
            operation.
        label_option: Only apply operations to the specified label instead of\
            all nonzero voxels.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriMorphologyOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_MORPHOLOGY_METADATA)
    cargs = []
    cargs.append("mri_morphology")
    cargs.append(execution.input_file(input_volume))
    cargs.append(operation)
    cargs.append(str(number_iter))
    cargs.append(execution.input_file(output_volume))
    if label_option is not None:
        cargs.extend([
            "-l",
            str(label_option)
        ])
    ret = MriMorphologyOutputs(
        root=execution.output_file("."),
        output_file=execution.output_file(pathlib.Path(output_volume).name),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_MORPHOLOGY_METADATA",
    "MriMorphologyOutputs",
    "mri_morphology",
]
