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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_ROBUST_REGISTER_METADATA = Metadata(
    id="fe2158f128fa82fc3156d764c03ca5f6fec2935c.boutiques",
    name="mri_robust_register",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriRobustRegisterOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_robust_register(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    reg_output: OutputPathType
    """Registration output file containing the transformation from movable to
    destination."""
    mapped_output: OutputPathType | None
    """Movable volume mapped and resampled at destination."""
    mapped_hdr_output: OutputPathType | None
    """Movable volume aligned to destination (header only)."""
    weights_output_file: OutputPathType | None
    """Weights indicating outlier probabilities in destination space."""
    iscale_out_file: OutputPathType | None
    """Output text file containing the intensity scale value."""
    half_mov_file: OutputPathType | None
    """Half-way movable volume resampled."""
    half_dst_file: OutputPathType | None
    """Half-way destination volume resampled."""
    half_weights_file: OutputPathType | None
    """Half-way weights resampled in halfway space."""
    half_mov_lta_file: OutputPathType | None
    """Transform output from movable to half-way space."""
    half_dst_lta_file: OutputPathType | None
    """Transform output from destination to half-way space."""
    ent_mov_file: OutputPathType | None
    """Movable entropy image for ROBENT cost function."""
    ent_dst_file: OutputPathType | None
    """Target entropy image for ROBENT cost function."""


def mri_robust_register(
    movable_volume: InputPathType,
    target_volume: InputPathType,
    output_registration: str,
    outlier_sensitivity: float | None = None,
    satit: bool = False,
    mapped_movable: str | None = None,
    mapped_movable_hdr: str | None = None,
    weights: str | None = None,
    oneminus_w: bool = False,
    iscale: bool = False,
    iscale_only: bool = False,
    iscale_out: str | None = None,
    iscale_in: str | None = None,
    trans_only: bool = False,
    affine: bool = False,
    ixform: str | None = None,
    init_orient: bool = False,
    no_init: bool = False,
    vox2vox: bool = False,
    cost: str | None = None,
    ent_radius: float | None = None,
    ent_correction: bool = False,
    ent_ball: bool = False,
    ent_mov: str | None = None,
    powell_tolerance: float | None = None,
    sobel: bool = False,
    no_sym: bool = False,
    maximum_iterations: float | None = None,
    ent_dst: str | None = None,
    high_iter: float | None = None,
    eps_iteration: float | None = None,
    no_multiscale: bool = False,
    max_size: float | None = None,
    min_size: float | None = None,
    w_limit: float | None = None,
    sub_sample: float | None = None,
    float_type: bool = False,
    white_bg_mov: bool = False,
    white_bg_dst: bool = False,
    uchar: bool = False,
    mask_mov: InputPathType | None = None,
    mask_dst: InputPathType | None = None,
    half_mov: str | None = None,
    half_dst: str | None = None,
    half_weights: str | None = None,
    half_mov_lta: str | None = None,
    half_dst_lta: str | None = None,
    debug: bool = False,
    verbose: float | None = None,
    runner: Runner | None = None,
) -> MriRobustRegisterOutputs:
    """
    Inverse consistent registration of two volumes using robust and standard cost
    functions.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        movable_volume: Input movable volume to be aligned to target.
        target_volume: Input target volume.
        output_registration: Output registration (transform from mov to dst).
        outlier_sensitivity: Set outlier sensitivity manually for robust cost\
            functions. Higher values mean less sensitivity.
        satit: Auto-detect good sensitivity for robust cost functions.
        mapped_movable: Output image: movable mapped and resampled at\
            destination.
        mapped_movable_hdr: Output image: movable aligned to destination (no\
            resampling, only adjusting header vox2ras).
        weights: Output weights (outlier probabilities) in destination space\
            (0=regular,1=outlier).
        oneminus_w: Weights (outlier) map will be inverted (0=outlier), as in\
            earlier versions.
        iscale: Estimate intensity scale factor.
        iscale_only: Only perform intensity scaling (no transformation).
        iscale_out: Output text file for iscale value.
        iscale_in: Initial input text file for iscale value.
        trans_only: Find 3 parameter translation only.
        affine: Find 12 parameter affine transform.
        ixform: Use initial transform LTA on source.
        init_orient: Use moments for orientation initialization.
        no_init: Skip automatic transform initialization.
        vox2vox: Output VOX2VOX LTA file.
        cost: Set cost function for registration.
        ent_radius: With ROBENT: specify box radius for entropy computation.
        ent_correction: With ROBENT: use better entropy computation that works\
            on smaller boxes.
        ent_ball: With ROBENT: use ball around voxel instead of box.
        ent_mov: With ROBENT: write movable entropy image.
        powell_tolerance: With MI, NMI etc: set Powell tolerance.
        sobel: Register Sobel magnitude images.
        no_sym: Do not map to half way space.
        maximum_iterations: Maximum number of iterations on each resolution.
        ent_dst: With ROBENT: write target entropy image.
        high_iter: Maximum number of iterations on highest resolution.
        eps_iteration: Stop iterations when transform update falls below\
            specified RMS distance.
        no_multiscale: Process highest resolution only (no multiscale).
        max_size: Specify largest voxel dimension for gaussian pyramid.
        min_size: Specify smallest voxel dimension for gaussian pyramid.
        w_limit: (Expert) sets maximal outlier limit for --satit.
        sub_sample: Subsample if dimension is greater than the specified value\
            on all axes.
        float_type: Convert images to float internally.
        white_bg_mov: Assume white background in MOV for padding.
        white_bg_dst: Assume white background in DST for padding.
        uchar: Convert inputs to UCHAR with rescale and histogram cropping.
        mask_mov: Mask movable image with mask file.
        mask_dst: Mask destination image with mask file.
        half_mov: Outputs half-way movable (resampled in halfway space).
        half_dst: Outputs half-way destination (resampled in halfway space).
        half_weights: Outputs half-way weights (resampled in halfway space).
        half_mov_lta: Outputs transform from movable to half-way space.
        half_dst_lta: Outputs transform from destination to half-way space.
        debug: Show debug output.
        verbose: Verbosity level: 0 (quiet), 1 (normal), 2 (detail).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriRobustRegisterOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_ROBUST_REGISTER_METADATA)
    cargs = []
    cargs.append("mri_robust_register")
    cargs.extend([
        "-mov",
        execution.input_file(movable_volume)
    ])
    cargs.extend([
        "-dst",
        execution.input_file(target_volume)
    ])
    cargs.extend([
        "-lta",
        output_registration
    ])
    if outlier_sensitivity is not None:
        cargs.extend([
            "--sat",
            str(outlier_sensitivity)
        ])
    if satit:
        cargs.append("--satit")
    if mapped_movable is not None:
        cargs.extend([
            "--mapmov",
            mapped_movable
        ])
    if mapped_movable_hdr is not None:
        cargs.extend([
            "--mapmovhdr",
            mapped_movable_hdr
        ])
    if weights is not None:
        cargs.extend([
            "--weights",
            weights
        ])
    if oneminus_w:
        cargs.append("--oneminusw")
    if iscale:
        cargs.append("--iscale")
    if iscale_only:
        cargs.append("--iscaleonly")
    if iscale_out is not None:
        cargs.extend([
            "--iscaleout",
            iscale_out
        ])
    if iscale_in is not None:
        cargs.extend([
            "--iscalein",
            iscale_in
        ])
    if trans_only:
        cargs.append("--transonly")
    if affine:
        cargs.append("--affine")
    if ixform is not None:
        cargs.extend([
            "--ixform",
            ixform
        ])
    if init_orient:
        cargs.append("--initorient")
    if no_init:
        cargs.append("--noinit")
    if vox2vox:
        cargs.append("--vox2vox")
    if cost is not None:
        cargs.extend([
            "--cost",
            cost
        ])
    if ent_radius is not None:
        cargs.extend([
            "--entradius",
            str(ent_radius)
        ])
    if ent_correction:
        cargs.append("--entcorrection")
    if ent_ball:
        cargs.append("--entball")
    if ent_mov is not None:
        cargs.extend([
            "--entmov",
            ent_mov
        ])
    if powell_tolerance is not None:
        cargs.extend([
            "--powelltol",
            str(powell_tolerance)
        ])
    if sobel:
        cargs.append("--sobel")
    if no_sym:
        cargs.append("--nosym")
    if maximum_iterations is not None:
        cargs.extend([
            "--maxit",
            str(maximum_iterations)
        ])
    if ent_dst is not None:
        cargs.extend([
            "--entdst",
            ent_dst
        ])
    if high_iter is not None:
        cargs.extend([
            "--highit",
            str(high_iter)
        ])
    if eps_iteration is not None:
        cargs.extend([
            "--epsit",
            str(eps_iteration)
        ])
    if no_multiscale:
        cargs.append("--nomulti")
    if max_size is not None:
        cargs.extend([
            "--maxsize",
            str(max_size)
        ])
    if min_size is not None:
        cargs.extend([
            "--minsize",
            str(min_size)
        ])
    if w_limit is not None:
        cargs.extend([
            "--wlimit",
            str(w_limit)
        ])
    if sub_sample is not None:
        cargs.extend([
            "--subsample",
            str(sub_sample)
        ])
    if float_type:
        cargs.append("--floattype")
    if white_bg_mov:
        cargs.append("--whitebgmov")
    if white_bg_dst:
        cargs.append("--whitebgdst")
    if uchar:
        cargs.append("--uchar")
    if mask_mov is not None:
        cargs.extend([
            "--maskmov",
            execution.input_file(mask_mov)
        ])
    if mask_dst is not None:
        cargs.extend([
            "--maskdst",
            execution.input_file(mask_dst)
        ])
    if half_mov is not None:
        cargs.extend([
            "--halfmov",
            half_mov
        ])
    if half_dst is not None:
        cargs.extend([
            "--halfdst",
            half_dst
        ])
    if half_weights is not None:
        cargs.extend([
            "--halfweights",
            half_weights
        ])
    if half_mov_lta is not None:
        cargs.extend([
            "--halfmovlta",
            half_mov_lta
        ])
    if half_dst_lta is not None:
        cargs.extend([
            "--halfdstlta",
            half_dst_lta
        ])
    if debug:
        cargs.append("--debug")
    if verbose is not None:
        cargs.extend([
            "--verbose",
            str(verbose)
        ])
    ret = MriRobustRegisterOutputs(
        root=execution.output_file("."),
        reg_output=execution.output_file(output_registration),
        mapped_output=execution.output_file(mapped_movable) if (mapped_movable is not None) else None,
        mapped_hdr_output=execution.output_file(mapped_movable_hdr) if (mapped_movable_hdr is not None) else None,
        weights_output_file=execution.output_file(weights) if (weights is not None) else None,
        iscale_out_file=execution.output_file(iscale_out) if (iscale_out is not None) else None,
        half_mov_file=execution.output_file(half_mov) if (half_mov is not None) else None,
        half_dst_file=execution.output_file(half_dst) if (half_dst is not None) else None,
        half_weights_file=execution.output_file(half_weights) if (half_weights is not None) else None,
        half_mov_lta_file=execution.output_file(half_mov_lta) if (half_mov_lta is not None) else None,
        half_dst_lta_file=execution.output_file(half_dst_lta) if (half_dst_lta is not None) else None,
        ent_mov_file=execution.output_file(ent_mov) if (ent_mov is not None) else None,
        ent_dst_file=execution.output_file(ent_dst) if (ent_dst is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_ROBUST_REGISTER_METADATA",
    "MriRobustRegisterOutputs",
    "mri_robust_register",
]
