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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_SYNTHSEG_METADATA = Metadata(
    id="576c0067650470dbfa8631765aae242b35b3480b.boutiques",
    name="mri_synthseg",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriSynthsegOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_synthseg(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_segmentation_file: OutputPathType
    """Segmentation output(s)"""
    output_volume_csv: OutputPathType | None
    """CSV file with volumes for all structures and subjects"""
    output_qc_csv: OutputPathType | None
    """CSV file with QC scores for all subjects"""
    output_posteriors_file: OutputPathType | None
    """Posteriors output(s)"""
    resampled_images_file: OutputPathType | None
    """Resampled image(s)"""


def mri_synthseg(
    input_image: InputPathType,
    output_segmentation: str,
    cortex_parcellation: bool = False,
    robust_prediction: bool = False,
    fast_prediction: bool = False,
    clip_ct: bool = False,
    output_volume: str | None = None,
    output_qc: str | None = None,
    output_posteriors: str | None = None,
    resampled_images: str | None = None,
    image_patch_size: list[float] | None = None,
    threads: float | None = None,
    cpu: bool = False,
    version_1: bool = False,
    photo_synthseg: str | None = None,
    runner: Runner | None = None,
) -> MriSynthsegOutputs:
    """
    SynthSeg is a tool for brain image segmentation.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        input_image: Image(s) to segment. Can be a path to an image or to a\
            folder.
        output_segmentation: Segmentation output(s). Must be a folder if --i\
            designates a folder.
        cortex_parcellation: Perform cortex parcellation.
        robust_prediction: Use robust predictions (slower).
        fast_prediction: Bypass some processing for faster prediction.
        clip_ct: Clip CT scans in Hounsfield scale to [0, 80].
        output_volume: Output CSV file with volumes for all structures and\
            subjects.
        output_qc: Output CSV file with QC scores for all subjects.
        output_posteriors: Posteriors output(s). Must be a folder if --i\
            designates a folder.
        resampled_images: Resampled image(s). Must be a folder if --i is a\
            folder.
        image_patch_size: Only analyse an image patch of the given size.
        threads: Number of cores to be used. Default is 1.
        cpu: Enforce running with CPU rather than GPU.
        version_1: Use SynthSeg 1.0 (updated 25/06/22).
        photo_synthseg: Photo-SynthSeg: segment 3D reconstructed stack of\
            coronal dissection photos of the cerebrum; must be left, right, or\
            both.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriSynthsegOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_SYNTHSEG_METADATA)
    cargs = []
    cargs.append("mri_synthseg")
    cargs.append(execution.input_file(input_image))
    cargs.append(output_segmentation)
    if cortex_parcellation:
        cargs.append("--parc")
    if robust_prediction:
        cargs.append("--robust")
    if fast_prediction:
        cargs.append("--fast")
    if clip_ct:
        cargs.append("--ct")
    if output_volume is not None:
        cargs.append(output_volume)
    if output_qc is not None:
        cargs.append(output_qc)
    if output_posteriors is not None:
        cargs.append(output_posteriors)
    if resampled_images is not None:
        cargs.append(resampled_images)
    if image_patch_size is not None:
        cargs.extend(map(str, image_patch_size))
    if threads is not None:
        cargs.append(str(threads))
    if cpu:
        cargs.append("--cpu")
    if version_1:
        cargs.append("--v1")
    if photo_synthseg is not None:
        cargs.append(photo_synthseg)
    ret = MriSynthsegOutputs(
        root=execution.output_file("."),
        output_segmentation_file=execution.output_file(output_segmentation),
        output_volume_csv=execution.output_file(output_volume) if (output_volume is not None) else None,
        output_qc_csv=execution.output_file(output_qc) if (output_qc is not None) else None,
        output_posteriors_file=execution.output_file(output_posteriors) if (output_posteriors is not None) else None,
        resampled_images_file=execution.output_file(resampled_images) if (resampled_images is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_SYNTHSEG_METADATA",
    "MriSynthsegOutputs",
    "mri_synthseg",
]
