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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_SYNTHSTRIP_METADATA = Metadata(
    id="404296260cedea4c55948a117336310c162854c6.boutiques",
    name="mri_synthstrip",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriSynthstripOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_synthstrip(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_image_file: OutputPathType | None
    """Stripped brain image output."""
    output_mask_file: OutputPathType | None
    """Binary brain mask output."""


def mri_synthstrip(
    image: InputPathType,
    output_image: InputPathType | None = None,
    mask: InputPathType | None = None,
    gpu: bool = False,
    border: float | None = 1,
    exclude_csf: bool = False,
    model_weights: InputPathType | None = None,
    runner: Runner | None = None,
) -> MriSynthstripOutputs:
    """
    Robust, universal skull-stripping for brain images of any type.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        image: Input image to skullstrip.
        output_image: Save stripped image to path.
        mask: Save binary brain mask to path.
        gpu: Use the GPU.
        border: Mask border threshold in mm. Default is 1.
        exclude_csf: Exclude CSF from brain border.
        model_weights: Alternative model weights.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriSynthstripOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_SYNTHSTRIP_METADATA)
    cargs = []
    cargs.append("mri_synthstrip")
    cargs.extend([
        "-i",
        execution.input_file(image)
    ])
    if output_image is not None:
        cargs.extend([
            "-o",
            "[" + execution.input_file(output_image) + "]"
        ])
    if mask is not None:
        cargs.extend([
            "-m",
            "[" + execution.input_file(mask) + "]"
        ])
    if gpu:
        cargs.append("[" + "-g" + "]")
    if border is not None:
        cargs.extend([
            "-b",
            "[" + str(border) + "]"
        ])
    if exclude_csf:
        cargs.append("[" + "--no-csf" + "]")
    if model_weights is not None:
        cargs.extend([
            "--model",
            "[" + execution.input_file(model_weights) + "]"
        ])
    ret = MriSynthstripOutputs(
        root=execution.output_file("."),
        output_image_file=execution.output_file(pathlib.Path(output_image).name) if (output_image is not None) else None,
        output_mask_file=execution.output_file(pathlib.Path(mask).name) if (mask is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_SYNTHSTRIP_METADATA",
    "MriSynthstripOutputs",
    "mri_synthstrip",
]
