# 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_METADATA = Metadata(
    id="ae946f4d1bb246c4c0e1a26e1d18d3d6f5ce930d.boutiques",
    name="ExtractRegionFromImage",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


@dataclasses.dataclass
class ExtractRegionFromImageRegionMinMaxIndex:
    min_index: str
    """Minimum index to define the starting point of the region."""
    max_index: str
    """Maximum index to define the endpoint of the region."""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append(self.min_index)
        cargs.append(self.max_index)
        return cargs


@dataclasses.dataclass
class ExtractRegionFromImageRegionLabel:
    label: str
    """Label value to extract the region corresponding to the specified
    label."""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append(self.label)
        return cargs


@dataclasses.dataclass
class ExtractRegionFromImageRegionDomainImage:
    domain_image: InputPathType
    """Image defining the domain from which to extract the region."""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append(execution.input_file(self.domain_image))
        return cargs


@dataclasses.dataclass
class ExtractRegionFromImageRegionLabelWithImage:
    label: str
    """Label value used for the region extraction."""
    label_image: InputPathType
    """Image containing label information."""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append(self.label)
        cargs.append(execution.input_file(self.label_image))
        cargs.append("1")
        return cargs


class ExtractRegionFromImageOutputs(typing.NamedTuple):
    """
    Output object returned when calling `extract_region_from_image(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_image_file: OutputPathType
    """File containing the extracted region."""


def extract_region_from_image(
    image_dimension: int,
    input_image: InputPathType,
    output_image: str,
    region_specification: typing.Union[ExtractRegionFromImageRegionMinMaxIndex, ExtractRegionFromImageRegionLabel, ExtractRegionFromImageRegionDomainImage, ExtractRegionFromImageRegionLabelWithImage],
    runner: Runner | None = None,
) -> ExtractRegionFromImageOutputs:
    """
    ExtractRegionFromImage can be used to extract a specific region from a given
    image. The region can be specified via indices, label, or another domain image.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        image_dimension: The dimensionality of the image.
        input_image: Path to the input image from which the region will be\
            extracted.
        output_image: Path to the output image where the extracted region will\
            be saved.
        region_specification: Specify the region to extract using indices,\
            label, domain image, or label with label image.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ExtractRegionFromImageOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(EXTRACT_REGION_FROM_IMAGE_METADATA)
    cargs = []
    cargs.append("ExtractRegionFromImage")
    cargs.append(str(image_dimension))
    cargs.append(execution.input_file(input_image))
    cargs.append(output_image)
    cargs.extend(region_specification.run(execution))
    ret = ExtractRegionFromImageOutputs(
        root=execution.output_file("."),
        output_image_file=execution.output_file(output_image),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "EXTRACT_REGION_FROM_IMAGE_METADATA",
    "ExtractRegionFromImageOutputs",
    "ExtractRegionFromImageRegionDomainImage",
    "ExtractRegionFromImageRegionLabel",
    "ExtractRegionFromImageRegionLabelWithImage",
    "ExtractRegionFromImageRegionMinMaxIndex",
    "extract_region_from_image",
]
