niwrap.ants.extract_region_from_image

  1# This file was auto generated by Styx.
  2# Do not edit this file directly.
  3
  4import typing
  5import pathlib
  6from styxdefs import *
  7
  8EXTRACT_REGION_FROM_IMAGE_METADATA = Metadata(
  9    id="ae946f4d1bb246c4c0e1a26e1d18d3d6f5ce930d.boutiques",
 10    name="ExtractRegionFromImage",
 11    package="ants",
 12    container_image_tag="antsx/ants:v2.5.3",
 13)
 14
 15
 16ExtractRegionFromImageRegionMinMaxIndexParameters = typing.TypedDict('ExtractRegionFromImageRegionMinMaxIndexParameters', {
 17    "__STYX_TYPE__": typing.Literal["region_min_max_index"],
 18    "min_index": str,
 19    "max_index": str,
 20})
 21
 22
 23ExtractRegionFromImageRegionLabelParameters = typing.TypedDict('ExtractRegionFromImageRegionLabelParameters', {
 24    "__STYX_TYPE__": typing.Literal["region_label"],
 25    "label": str,
 26})
 27
 28
 29ExtractRegionFromImageRegionDomainImageParameters = typing.TypedDict('ExtractRegionFromImageRegionDomainImageParameters', {
 30    "__STYX_TYPE__": typing.Literal["region_domain_image"],
 31    "domain_image": InputPathType,
 32})
 33
 34
 35ExtractRegionFromImageRegionLabelWithImageParameters = typing.TypedDict('ExtractRegionFromImageRegionLabelWithImageParameters', {
 36    "__STYX_TYPE__": typing.Literal["region_label_with_image"],
 37    "label": str,
 38    "label_image": InputPathType,
 39})
 40
 41
 42ExtractRegionFromImageParameters = typing.TypedDict('ExtractRegionFromImageParameters', {
 43    "__STYX_TYPE__": typing.Literal["ExtractRegionFromImage"],
 44    "image_dimension": int,
 45    "input_image": InputPathType,
 46    "output_image": str,
 47    "region_specification": typing.Union[ExtractRegionFromImageRegionMinMaxIndexParameters, ExtractRegionFromImageRegionLabelParameters, ExtractRegionFromImageRegionDomainImageParameters, ExtractRegionFromImageRegionLabelWithImageParameters],
 48})
 49
 50
 51def dyn_cargs(
 52    t: str,
 53) -> typing.Any:
 54    """
 55    Get build cargs function by command type.
 56    
 57    Args:
 58        t: Command type.
 59    Returns:
 60        Build cargs function.
 61    """
 62    return {
 63        "ExtractRegionFromImage": extract_region_from_image_cargs,
 64        "region_min_max_index": extract_region_from_image_region_min_max_index_cargs,
 65        "region_label": extract_region_from_image_region_label_cargs,
 66        "region_domain_image": extract_region_from_image_region_domain_image_cargs,
 67        "region_label_with_image": extract_region_from_image_region_label_with_image_cargs,
 68    }.get(t)
 69
 70
 71def dyn_outputs(
 72    t: str,
 73) -> typing.Any:
 74    """
 75    Get build outputs function by command type.
 76    
 77    Args:
 78        t: Command type.
 79    Returns:
 80        Build outputs function.
 81    """
 82    return {
 83        "ExtractRegionFromImage": extract_region_from_image_outputs,
 84    }.get(t)
 85
 86
 87def extract_region_from_image_region_min_max_index_params(
 88    min_index: str,
 89    max_index: str,
 90) -> ExtractRegionFromImageRegionMinMaxIndexParameters:
 91    """
 92    Build parameters.
 93    
 94    Args:
 95        min_index: Minimum index to define the starting point of the region.
 96        max_index: Maximum index to define the endpoint of the region.
 97    Returns:
 98        Parameter dictionary
 99    """
100    params = {
101        "__STYXTYPE__": "region_min_max_index",
102        "min_index": min_index,
103        "max_index": max_index,
104    }
105    return params
106
107
108def extract_region_from_image_region_min_max_index_cargs(
109    params: ExtractRegionFromImageRegionMinMaxIndexParameters,
110    execution: Execution,
111) -> list[str]:
112    """
113    Build command-line arguments from parameters.
114    
115    Args:
116        params: The parameters.
117        execution: The execution object for resolving input paths.
118    Returns:
119        Command-line arguments.
120    """
121    cargs = []
122    cargs.append(params.get("min_index"))
123    cargs.append(params.get("max_index"))
124    return cargs
125
126
127def extract_region_from_image_region_label_params(
128    label: str,
129) -> ExtractRegionFromImageRegionLabelParameters:
130    """
131    Build parameters.
132    
133    Args:
134        label: Label value to extract the region corresponding to the specified\
135            label.
136    Returns:
137        Parameter dictionary
138    """
139    params = {
140        "__STYXTYPE__": "region_label",
141        "label": label,
142    }
143    return params
144
145
146def extract_region_from_image_region_label_cargs(
147    params: ExtractRegionFromImageRegionLabelParameters,
148    execution: Execution,
149) -> list[str]:
150    """
151    Build command-line arguments from parameters.
152    
153    Args:
154        params: The parameters.
155        execution: The execution object for resolving input paths.
156    Returns:
157        Command-line arguments.
158    """
159    cargs = []
160    cargs.append(params.get("label"))
161    return cargs
162
163
164def extract_region_from_image_region_domain_image_params(
165    domain_image: InputPathType,
166) -> ExtractRegionFromImageRegionDomainImageParameters:
167    """
168    Build parameters.
169    
170    Args:
171        domain_image: Image defining the domain from which to extract the\
172            region.
173    Returns:
174        Parameter dictionary
175    """
176    params = {
177        "__STYXTYPE__": "region_domain_image",
178        "domain_image": domain_image,
179    }
180    return params
181
182
183def extract_region_from_image_region_domain_image_cargs(
184    params: ExtractRegionFromImageRegionDomainImageParameters,
185    execution: Execution,
186) -> list[str]:
187    """
188    Build command-line arguments from parameters.
189    
190    Args:
191        params: The parameters.
192        execution: The execution object for resolving input paths.
193    Returns:
194        Command-line arguments.
195    """
196    cargs = []
197    cargs.append(execution.input_file(params.get("domain_image")))
198    return cargs
199
200
201def extract_region_from_image_region_label_with_image_params(
202    label: str,
203    label_image: InputPathType,
204) -> ExtractRegionFromImageRegionLabelWithImageParameters:
205    """
206    Build parameters.
207    
208    Args:
209        label: Label value used for the region extraction.
210        label_image: Image containing label information.
211    Returns:
212        Parameter dictionary
213    """
214    params = {
215        "__STYXTYPE__": "region_label_with_image",
216        "label": label,
217        "label_image": label_image,
218    }
219    return params
220
221
222def extract_region_from_image_region_label_with_image_cargs(
223    params: ExtractRegionFromImageRegionLabelWithImageParameters,
224    execution: Execution,
225) -> list[str]:
226    """
227    Build command-line arguments from parameters.
228    
229    Args:
230        params: The parameters.
231        execution: The execution object for resolving input paths.
232    Returns:
233        Command-line arguments.
234    """
235    cargs = []
236    cargs.append(params.get("label"))
237    cargs.append(execution.input_file(params.get("label_image")))
238    cargs.append("1")
239    return cargs
240
241
242class ExtractRegionFromImageOutputs(typing.NamedTuple):
243    """
244    Output object returned when calling `extract_region_from_image(...)`.
245    """
246    root: OutputPathType
247    """Output root folder. This is the root folder for all outputs."""
248    output_image_file: OutputPathType
249    """File containing the extracted region."""
250
251
252def extract_region_from_image_params(
253    image_dimension: int,
254    input_image: InputPathType,
255    output_image: str,
256    region_specification: typing.Union[ExtractRegionFromImageRegionMinMaxIndexParameters, ExtractRegionFromImageRegionLabelParameters, ExtractRegionFromImageRegionDomainImageParameters, ExtractRegionFromImageRegionLabelWithImageParameters],
257) -> ExtractRegionFromImageParameters:
258    """
259    Build parameters.
260    
261    Args:
262        image_dimension: The dimensionality of the image.
263        input_image: Path to the input image from which the region will be\
264            extracted.
265        output_image: Path to the output image where the extracted region will\
266            be saved.
267        region_specification: Specify the region to extract using indices,\
268            label, domain image, or label with label image.
269    Returns:
270        Parameter dictionary
271    """
272    params = {
273        "__STYXTYPE__": "ExtractRegionFromImage",
274        "image_dimension": image_dimension,
275        "input_image": input_image,
276        "output_image": output_image,
277        "region_specification": region_specification,
278    }
279    return params
280
281
282def extract_region_from_image_cargs(
283    params: ExtractRegionFromImageParameters,
284    execution: Execution,
285) -> list[str]:
286    """
287    Build command-line arguments from parameters.
288    
289    Args:
290        params: The parameters.
291        execution: The execution object for resolving input paths.
292    Returns:
293        Command-line arguments.
294    """
295    cargs = []
296    cargs.append("ExtractRegionFromImage")
297    cargs.append(str(params.get("image_dimension")))
298    cargs.append(execution.input_file(params.get("input_image")))
299    cargs.append(params.get("output_image"))
300    cargs.extend(dyn_cargs(params.get("region_specification")["__STYXTYPE__"])(params.get("region_specification"), execution))
301    return cargs
302
303
304def extract_region_from_image_outputs(
305    params: ExtractRegionFromImageParameters,
306    execution: Execution,
307) -> ExtractRegionFromImageOutputs:
308    """
309    Build outputs object containing output file paths and possibly stdout/stderr.
310    
311    Args:
312        params: The parameters.
313        execution: The execution object for resolving input paths.
314    Returns:
315        Outputs object.
316    """
317    ret = ExtractRegionFromImageOutputs(
318        root=execution.output_file("."),
319        output_image_file=execution.output_file(params.get("output_image")),
320    )
321    return ret
322
323
324def extract_region_from_image_execute(
325    params: ExtractRegionFromImageParameters,
326    execution: Execution,
327) -> ExtractRegionFromImageOutputs:
328    """
329    ExtractRegionFromImage can be used to extract a specific region from a given
330    image. The region can be specified via indices, label, or another domain image.
331    
332    Author: ANTs Developers
333    
334    URL: https://github.com/ANTsX/ANTs
335    
336    Args:
337        params: The parameters.
338        execution: The execution object.
339    Returns:
340        NamedTuple of outputs (described in `ExtractRegionFromImageOutputs`).
341    """
342    params = execution.params(params)
343    cargs = extract_region_from_image_cargs(params, execution)
344    ret = extract_region_from_image_outputs(params, execution)
345    execution.run(cargs)
346    return ret
347
348
349def extract_region_from_image(
350    image_dimension: int,
351    input_image: InputPathType,
352    output_image: str,
353    region_specification: typing.Union[ExtractRegionFromImageRegionMinMaxIndexParameters, ExtractRegionFromImageRegionLabelParameters, ExtractRegionFromImageRegionDomainImageParameters, ExtractRegionFromImageRegionLabelWithImageParameters],
354    runner: Runner | None = None,
355) -> ExtractRegionFromImageOutputs:
356    """
357    ExtractRegionFromImage can be used to extract a specific region from a given
358    image. The region can be specified via indices, label, or another domain image.
359    
360    Author: ANTs Developers
361    
362    URL: https://github.com/ANTsX/ANTs
363    
364    Args:
365        image_dimension: The dimensionality of the image.
366        input_image: Path to the input image from which the region will be\
367            extracted.
368        output_image: Path to the output image where the extracted region will\
369            be saved.
370        region_specification: Specify the region to extract using indices,\
371            label, domain image, or label with label image.
372        runner: Command runner.
373    Returns:
374        NamedTuple of outputs (described in `ExtractRegionFromImageOutputs`).
375    """
376    runner = runner or get_global_runner()
377    execution = runner.start_execution(EXTRACT_REGION_FROM_IMAGE_METADATA)
378    params = extract_region_from_image_params(
379        image_dimension=image_dimension,
380        input_image=input_image,
381        output_image=output_image,
382        region_specification=region_specification,
383    )
384    return extract_region_from_image_execute(params, execution)
385
386
387__all__ = [
388    "EXTRACT_REGION_FROM_IMAGE_METADATA",
389    "ExtractRegionFromImageOutputs",
390    "ExtractRegionFromImageParameters",
391    "ExtractRegionFromImageRegionDomainImageParameters",
392    "ExtractRegionFromImageRegionLabelParameters",
393    "ExtractRegionFromImageRegionLabelWithImageParameters",
394    "ExtractRegionFromImageRegionMinMaxIndexParameters",
395    "extract_region_from_image",
396    "extract_region_from_image_params",
397    "extract_region_from_image_region_domain_image_params",
398    "extract_region_from_image_region_label_params",
399    "extract_region_from_image_region_label_with_image_params",
400    "extract_region_from_image_region_min_max_index_params",
401]
EXTRACT_REGION_FROM_IMAGE_METADATA = Metadata(id='ae946f4d1bb246c4c0e1a26e1d18d3d6f5ce930d.boutiques', name='ExtractRegionFromImage', package='ants', citations=None, container_image_tag='antsx/ants:v2.5.3')
class ExtractRegionFromImageOutputs(typing.NamedTuple):
243class ExtractRegionFromImageOutputs(typing.NamedTuple):
244    """
245    Output object returned when calling `extract_region_from_image(...)`.
246    """
247    root: OutputPathType
248    """Output root folder. This is the root folder for all outputs."""
249    output_image_file: OutputPathType
250    """File containing the extracted region."""

Output object returned when calling extract_region_from_image(...).

ExtractRegionFromImageOutputs(root: pathlib._local.Path, output_image_file: pathlib._local.Path)

Create new instance of ExtractRegionFromImageOutputs(root, output_image_file)

root: pathlib._local.Path

Output root folder. This is the root folder for all outputs.

output_image_file: pathlib._local.Path

File containing the extracted region.

class ExtractRegionFromImageParameters(typing.TypedDict):
image_dimension: int
input_image: pathlib._local.Path | str
output_image: str
class ExtractRegionFromImageRegionDomainImageParameters(typing.TypedDict):
domain_image: pathlib._local.Path | str
class ExtractRegionFromImageRegionLabelParameters(typing.TypedDict):
label: str
class ExtractRegionFromImageRegionLabelWithImageParameters(typing.TypedDict):
label: str
label_image: pathlib._local.Path | str
class ExtractRegionFromImageRegionMinMaxIndexParameters(typing.TypedDict):
min_index: str
max_index: str
def extract_region_from_image( image_dimension: int, input_image: pathlib._local.Path | str, output_image: str, region_specification: Union[ExtractRegionFromImageRegionMinMaxIndexParameters, ExtractRegionFromImageRegionLabelParameters, ExtractRegionFromImageRegionDomainImageParameters, ExtractRegionFromImageRegionLabelWithImageParameters], runner: styxdefs.types.Runner | None = None) -> ExtractRegionFromImageOutputs:
350def extract_region_from_image(
351    image_dimension: int,
352    input_image: InputPathType,
353    output_image: str,
354    region_specification: typing.Union[ExtractRegionFromImageRegionMinMaxIndexParameters, ExtractRegionFromImageRegionLabelParameters, ExtractRegionFromImageRegionDomainImageParameters, ExtractRegionFromImageRegionLabelWithImageParameters],
355    runner: Runner | None = None,
356) -> ExtractRegionFromImageOutputs:
357    """
358    ExtractRegionFromImage can be used to extract a specific region from a given
359    image. The region can be specified via indices, label, or another domain image.
360    
361    Author: ANTs Developers
362    
363    URL: https://github.com/ANTsX/ANTs
364    
365    Args:
366        image_dimension: The dimensionality of the image.
367        input_image: Path to the input image from which the region will be\
368            extracted.
369        output_image: Path to the output image where the extracted region will\
370            be saved.
371        region_specification: Specify the region to extract using indices,\
372            label, domain image, or label with label image.
373        runner: Command runner.
374    Returns:
375        NamedTuple of outputs (described in `ExtractRegionFromImageOutputs`).
376    """
377    runner = runner or get_global_runner()
378    execution = runner.start_execution(EXTRACT_REGION_FROM_IMAGE_METADATA)
379    params = extract_region_from_image_params(
380        image_dimension=image_dimension,
381        input_image=input_image,
382        output_image=output_image,
383        region_specification=region_specification,
384    )
385    return extract_region_from_image_execute(params, execution)

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

Arguments:
  • 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).

def extract_region_from_image_params( image_dimension: int, input_image: pathlib._local.Path | str, output_image: str, region_specification: Union[ExtractRegionFromImageRegionMinMaxIndexParameters, ExtractRegionFromImageRegionLabelParameters, ExtractRegionFromImageRegionDomainImageParameters, ExtractRegionFromImageRegionLabelWithImageParameters]) -> ExtractRegionFromImageParameters:
253def extract_region_from_image_params(
254    image_dimension: int,
255    input_image: InputPathType,
256    output_image: str,
257    region_specification: typing.Union[ExtractRegionFromImageRegionMinMaxIndexParameters, ExtractRegionFromImageRegionLabelParameters, ExtractRegionFromImageRegionDomainImageParameters, ExtractRegionFromImageRegionLabelWithImageParameters],
258) -> ExtractRegionFromImageParameters:
259    """
260    Build parameters.
261    
262    Args:
263        image_dimension: The dimensionality of the image.
264        input_image: Path to the input image from which the region will be\
265            extracted.
266        output_image: Path to the output image where the extracted region will\
267            be saved.
268        region_specification: Specify the region to extract using indices,\
269            label, domain image, or label with label image.
270    Returns:
271        Parameter dictionary
272    """
273    params = {
274        "__STYXTYPE__": "ExtractRegionFromImage",
275        "image_dimension": image_dimension,
276        "input_image": input_image,
277        "output_image": output_image,
278        "region_specification": region_specification,
279    }
280    return params

Build parameters.

Arguments:
  • 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.
Returns:

Parameter dictionary

def extract_region_from_image_region_domain_image_params( domain_image: pathlib._local.Path | str) -> ExtractRegionFromImageRegionDomainImageParameters:
165def extract_region_from_image_region_domain_image_params(
166    domain_image: InputPathType,
167) -> ExtractRegionFromImageRegionDomainImageParameters:
168    """
169    Build parameters.
170    
171    Args:
172        domain_image: Image defining the domain from which to extract the\
173            region.
174    Returns:
175        Parameter dictionary
176    """
177    params = {
178        "__STYXTYPE__": "region_domain_image",
179        "domain_image": domain_image,
180    }
181    return params

Build parameters.

Arguments:
  • domain_image: Image defining the domain from which to extract the region.
Returns:

Parameter dictionary

def extract_region_from_image_region_label_params( label: str) -> ExtractRegionFromImageRegionLabelParameters:
128def extract_region_from_image_region_label_params(
129    label: str,
130) -> ExtractRegionFromImageRegionLabelParameters:
131    """
132    Build parameters.
133    
134    Args:
135        label: Label value to extract the region corresponding to the specified\
136            label.
137    Returns:
138        Parameter dictionary
139    """
140    params = {
141        "__STYXTYPE__": "region_label",
142        "label": label,
143    }
144    return params

Build parameters.

Arguments:
  • label: Label value to extract the region corresponding to the specified label.
Returns:

Parameter dictionary

def extract_region_from_image_region_label_with_image_params( label: str, label_image: pathlib._local.Path | str) -> ExtractRegionFromImageRegionLabelWithImageParameters:
202def extract_region_from_image_region_label_with_image_params(
203    label: str,
204    label_image: InputPathType,
205) -> ExtractRegionFromImageRegionLabelWithImageParameters:
206    """
207    Build parameters.
208    
209    Args:
210        label: Label value used for the region extraction.
211        label_image: Image containing label information.
212    Returns:
213        Parameter dictionary
214    """
215    params = {
216        "__STYXTYPE__": "region_label_with_image",
217        "label": label,
218        "label_image": label_image,
219    }
220    return params

Build parameters.

Arguments:
  • label: Label value used for the region extraction.
  • label_image: Image containing label information.
Returns:

Parameter dictionary

def extract_region_from_image_region_min_max_index_params( min_index: str, max_index: str) -> ExtractRegionFromImageRegionMinMaxIndexParameters:
 88def extract_region_from_image_region_min_max_index_params(
 89    min_index: str,
 90    max_index: str,
 91) -> ExtractRegionFromImageRegionMinMaxIndexParameters:
 92    """
 93    Build parameters.
 94    
 95    Args:
 96        min_index: Minimum index to define the starting point of the region.
 97        max_index: Maximum index to define the endpoint of the region.
 98    Returns:
 99        Parameter dictionary
100    """
101    params = {
102        "__STYXTYPE__": "region_min_max_index",
103        "min_index": min_index,
104        "max_index": max_index,
105    }
106    return params

Build parameters.

Arguments:
  • min_index: Minimum index to define the starting point of the region.
  • max_index: Maximum index to define the endpoint of the region.
Returns:

Parameter dictionary