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

import typing
import pathlib
from styxdefs import *
import dataclasses

EXTRACT_REGION_FROM_IMAGE_BY_MASK_METADATA = Metadata(
    id="aec2f60db8048987a495410600ad2f857750da61.boutiques",
    name="ExtractRegionFromImageByMask",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


class ExtractRegionFromImageByMaskOutputs(typing.NamedTuple):
    """
    Output object returned when calling `extract_region_from_image_by_mask(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""


def extract_region_from_image_by_mask(
    image_dimension: int,
    input_image: InputPathType,
    output_image: InputPathType,
    label_mask_image: InputPathType,
    label: int | None = 1,
    pad_radius: int | None = 0,
    runner: Runner | None = None,
) -> ExtractRegionFromImageByMaskOutputs:
    """
    Extract a sub-region from an image using the bounding box from a label image,
    with an optional padding radius.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        image_dimension: Dimension of the input image.
        input_image: The input image from which a region will be extracted.
        output_image: The output image containing the extracted region.
        label_mask_image: The label mask image used to extract the bounding\
            box.
        label: The label value used to extract the sub-region.
        pad_radius: Optional padding radius to be added around the bounding\
            box.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ExtractRegionFromImageByMaskOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(EXTRACT_REGION_FROM_IMAGE_BY_MASK_METADATA)
    cargs = []
    cargs.append("ExtractRegionFromImageByMask")
    cargs.append(str(image_dimension))
    cargs.append(execution.input_file(input_image))
    cargs.append(execution.input_file(output_image))
    cargs.append(execution.input_file(label_mask_image))
    if label is not None:
        cargs.append(str(label))
    if pad_radius is not None:
        cargs.append(str(pad_radius))
    ret = ExtractRegionFromImageByMaskOutputs(
        root=execution.output_file("."),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "EXTRACT_REGION_FROM_IMAGE_BY_MASK_METADATA",
    "ExtractRegionFromImageByMaskOutputs",
    "extract_region_from_image_by_mask",
]
