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

import typing
import pathlib
from styxdefs import *

NON_LOCAL_SUPER_RESOLUTION_METADATA = Metadata(
    id="51aada9b4dbce0b9d25369841901cb709639d1e3.boutiques",
    name="NonLocalSuperResolution",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


NonLocalSuperResolutionParameters = typing.TypedDict('NonLocalSuperResolutionParameters', {
    "__STYX_TYPE__": typing.Literal["NonLocalSuperResolution"],
    "image_dimensionality": typing.NotRequired[typing.Literal[2, 3, 4] | None],
    "input_image": InputPathType,
    "interpolated_image": typing.NotRequired[InputPathType | None],
    "reference_image": typing.NotRequired[InputPathType | None],
    "patch_radius": typing.NotRequired[typing.Literal["1", "1x1x1"] | None],
    "search_radius": typing.NotRequired[typing.Literal["3", "3x3x3"] | None],
    "intensity_difference_sigma": typing.NotRequired[float | None],
    "patch_similarity_sigma": typing.NotRequired[float | None],
    "scale_levels": typing.NotRequired[str | None],
    "interpolation": typing.NotRequired[typing.Literal["Linear", "NearestNeighbor", "Gaussian", "BSpline", "CosineWindowedSinc", "WelchWindowedSinc", "HammingWindowedSinc", "LanczosWindowedSinc"] | None],
    "output": str,
    "verbose": typing.NotRequired[typing.Literal[0, 1] | None],
})


def dyn_cargs(
    t: str,
) -> typing.Any:
    """
    Get build cargs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build cargs function.
    """
    return {
        "NonLocalSuperResolution": non_local_super_resolution_cargs,
    }.get(t)


def dyn_outputs(
    t: str,
) -> typing.Any:
    """
    Get build outputs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build outputs function.
    """
    return {
        "NonLocalSuperResolution": non_local_super_resolution_outputs,
    }.get(t)


class NonLocalSuperResolutionOutputs(typing.NamedTuple):
    """
    Output object returned when calling `non_local_super_resolution(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    superresoluted_output: OutputPathType
    """The superresoluted output image."""


def non_local_super_resolution_params(
    input_image: InputPathType,
    output: str,
    image_dimensionality: typing.Literal[2, 3, 4] | None = None,
    interpolated_image: InputPathType | None = None,
    reference_image: InputPathType | None = None,
    patch_radius: typing.Literal["1", "1x1x1"] | None = None,
    search_radius: typing.Literal["3", "3x3x3"] | None = None,
    intensity_difference_sigma: float | None = 1.0,
    patch_similarity_sigma: float | None = 1.0,
    scale_levels: str | None = "32x16x8x2x1",
    interpolation: typing.Literal["Linear", "NearestNeighbor", "Gaussian", "BSpline", "CosineWindowedSinc", "WelchWindowedSinc", "HammingWindowedSinc", "LanczosWindowedSinc"] | None = None,
    verbose: typing.Literal[0, 1] | None = None,
) -> NonLocalSuperResolutionParameters:
    """
    Build parameters.
    
    Args:
        input_image: A low-resolution input image to be superresoluted.
        output: The output consists of the noise corrected version of the input\
            image. Optionally, one can also output the estimated noise image.
        image_dimensionality: This option forces the image to be treated as a\
            specified-dimensional image. If not specified, the program tries to\
            infer the dimensionality from the input image.
        interpolated_image: An interpolated version of the low-resolution image\
            (such as B-spline). Specify either this option or a high-resolution\
            multi-modal counterpart (cf the -k option).
        reference_image: A high-resolution reference multi-modal image. Assumed\
            to be in the same space as the low-resolution input image. Specify\
            either this option or an interpolated version (cf the -j option).
        patch_radius: Patch radius. Default = 1x1x1.
        search_radius: Search radius. Default = 3x3x3.
        intensity_difference_sigma: Intensity difference sigma. Default = 1.0.
        patch_similarity_sigma: Patch similarity sigma. Default = 1.0.
        scale_levels: Scale levels. Default = 32x16x8x2x1.
        interpolation: Several interpolation options are available in ITK.
        verbose: Verbose output.
    Returns:
        Parameter dictionary
    """
    params = {
        "__STYXTYPE__": "NonLocalSuperResolution",
        "input_image": input_image,
        "output": output,
    }
    if image_dimensionality is not None:
        params["image_dimensionality"] = image_dimensionality
    if interpolated_image is not None:
        params["interpolated_image"] = interpolated_image
    if reference_image is not None:
        params["reference_image"] = reference_image
    if patch_radius is not None:
        params["patch_radius"] = patch_radius
    if search_radius is not None:
        params["search_radius"] = search_radius
    if intensity_difference_sigma is not None:
        params["intensity_difference_sigma"] = intensity_difference_sigma
    if patch_similarity_sigma is not None:
        params["patch_similarity_sigma"] = patch_similarity_sigma
    if scale_levels is not None:
        params["scale_levels"] = scale_levels
    if interpolation is not None:
        params["interpolation"] = interpolation
    if verbose is not None:
        params["verbose"] = verbose
    return params


def non_local_super_resolution_cargs(
    params: NonLocalSuperResolutionParameters,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("NonLocalSuperResolution")
    if params.get("image_dimensionality") is not None:
        cargs.extend([
            "-d",
            str(params.get("image_dimensionality"))
        ])
    cargs.extend([
        "-i",
        execution.input_file(params.get("input_image"))
    ])
    if params.get("interpolated_image") is not None:
        cargs.extend([
            "-j",
            execution.input_file(params.get("interpolated_image"))
        ])
    if params.get("reference_image") is not None:
        cargs.extend([
            "-k",
            execution.input_file(params.get("reference_image"))
        ])
    if params.get("patch_radius") is not None:
        cargs.extend([
            "-p",
            params.get("patch_radius")
        ])
    if params.get("search_radius") is not None:
        cargs.extend([
            "-r",
            params.get("search_radius")
        ])
    if params.get("intensity_difference_sigma") is not None:
        cargs.extend([
            "-g",
            str(params.get("intensity_difference_sigma"))
        ])
    if params.get("patch_similarity_sigma") is not None:
        cargs.extend([
            "-t",
            str(params.get("patch_similarity_sigma"))
        ])
    if params.get("scale_levels") is not None:
        cargs.extend([
            "-s",
            params.get("scale_levels")
        ])
    if params.get("interpolation") is not None:
        cargs.extend([
            "-n",
            params.get("interpolation")
        ])
    cargs.extend([
        "-o",
        params.get("output")
    ])
    if params.get("verbose") is not None:
        cargs.extend([
            "-v",
            str(params.get("verbose"))
        ])
    return cargs


def non_local_super_resolution_outputs(
    params: NonLocalSuperResolutionParameters,
    execution: Execution,
) -> NonLocalSuperResolutionOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = NonLocalSuperResolutionOutputs(
        root=execution.output_file("."),
        superresoluted_output=execution.output_file(params.get("output")),
    )
    return ret


def non_local_super_resolution_execute(
    params: NonLocalSuperResolutionParameters,
    execution: Execution,
) -> NonLocalSuperResolutionOutputs:
    """
    Non-local super resolution described in the papers by JV Manjon et al., focusing
    on MRI superresolution using self-similarity and image priors.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        execution: The execution object.
    Returns:
        NamedTuple of outputs (described in `NonLocalSuperResolutionOutputs`).
    """
    params = execution.params(params)
    cargs = non_local_super_resolution_cargs(params, execution)
    ret = non_local_super_resolution_outputs(params, execution)
    execution.run(cargs)
    return ret


def non_local_super_resolution(
    input_image: InputPathType,
    output: str,
    image_dimensionality: typing.Literal[2, 3, 4] | None = None,
    interpolated_image: InputPathType | None = None,
    reference_image: InputPathType | None = None,
    patch_radius: typing.Literal["1", "1x1x1"] | None = None,
    search_radius: typing.Literal["3", "3x3x3"] | None = None,
    intensity_difference_sigma: float | None = 1.0,
    patch_similarity_sigma: float | None = 1.0,
    scale_levels: str | None = "32x16x8x2x1",
    interpolation: typing.Literal["Linear", "NearestNeighbor", "Gaussian", "BSpline", "CosineWindowedSinc", "WelchWindowedSinc", "HammingWindowedSinc", "LanczosWindowedSinc"] | None = None,
    verbose: typing.Literal[0, 1] | None = None,
    runner: Runner | None = None,
) -> NonLocalSuperResolutionOutputs:
    """
    Non-local super resolution described in the papers by JV Manjon et al., focusing
    on MRI superresolution using self-similarity and image priors.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        input_image: A low-resolution input image to be superresoluted.
        output: The output consists of the noise corrected version of the input\
            image. Optionally, one can also output the estimated noise image.
        image_dimensionality: This option forces the image to be treated as a\
            specified-dimensional image. If not specified, the program tries to\
            infer the dimensionality from the input image.
        interpolated_image: An interpolated version of the low-resolution image\
            (such as B-spline). Specify either this option or a high-resolution\
            multi-modal counterpart (cf the -k option).
        reference_image: A high-resolution reference multi-modal image. Assumed\
            to be in the same space as the low-resolution input image. Specify\
            either this option or an interpolated version (cf the -j option).
        patch_radius: Patch radius. Default = 1x1x1.
        search_radius: Search radius. Default = 3x3x3.
        intensity_difference_sigma: Intensity difference sigma. Default = 1.0.
        patch_similarity_sigma: Patch similarity sigma. Default = 1.0.
        scale_levels: Scale levels. Default = 32x16x8x2x1.
        interpolation: Several interpolation options are available in ITK.
        verbose: Verbose output.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `NonLocalSuperResolutionOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(NON_LOCAL_SUPER_RESOLUTION_METADATA)
    params = non_local_super_resolution_params(
        image_dimensionality=image_dimensionality,
        input_image=input_image,
        interpolated_image=interpolated_image,
        reference_image=reference_image,
        patch_radius=patch_radius,
        search_radius=search_radius,
        intensity_difference_sigma=intensity_difference_sigma,
        patch_similarity_sigma=patch_similarity_sigma,
        scale_levels=scale_levels,
        interpolation=interpolation,
        output=output,
        verbose=verbose,
    )
    return non_local_super_resolution_execute(params, execution)


__all__ = [
    "NON_LOCAL_SUPER_RESOLUTION_METADATA",
    "NonLocalSuperResolutionOutputs",
    "NonLocalSuperResolutionParameters",
    "non_local_super_resolution",
    "non_local_super_resolution_params",
]
