Imageutils
imageutils
#
Functions:
Name | Description |
---|---|
array_to_image |
Convert a numpy array to a SimpleITK image with optional metadata. |
idxs_to_physical_points |
Converts image indices to physical points based on the reference image's |
image_to_array |
Convert a SimpleITK image to a numpy array along with its metadata. |
physical_points_to_idxs |
Convert physical points to image indices based on the reference image's |
array_to_image
#
array_to_image(
array: numpy.ndarray,
origin: imgtools.utils.imageutils.Array3D = (
0.0,
0.0,
0.0,
),
direction: typing.Tuple[float, ...] = (
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
),
spacing: imgtools.utils.imageutils.Array3D = (
1.0,
1.0,
1.0,
),
reference_image: SimpleITK.Image | None = None,
) -> SimpleITK.Image
Convert a numpy array to a SimpleITK image with optional metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
numpy.ndarray
|
The numpy array to convert. |
required |
|
imgtools.utils.imageutils.Array3D
|
The origin of the image (default is (0.0, 0.0, 0.0)). |
(0.0, 0.0, 0.0)
|
|
typing.Tuple[float, ...]
|
The direction cosines of the image (default is identity matrix). |
(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)
|
|
imgtools.utils.imageutils.Array3D
|
The pixel spacing of the image (default is (1.0, 1.0, 1.0)). |
(1.0, 1.0, 1.0)
|
|
SimpleITK.Image
|
A reference SimpleITK image to copy metadata from (default is None). |
None
|
Returns:
Type | Description |
---|---|
SimpleITK.Image
|
The resulting SimpleITK image. |
Source code in src/imgtools/utils/imageutils.py
idxs_to_physical_points
#
Converts image indices to physical points based on the reference image's geometry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
SimpleITK.Image
|
The reference SimpleITK image. |
required |
|
numpy.ndarray
|
Array of 3D indices (continuous or discrete). |
required |
Returns:
Type | Description |
---|---|
numpy.ndarray
|
Physical coordinates corresponding to the given indices. |
Source code in src/imgtools/utils/imageutils.py
image_to_array
#
image_to_array(
image: SimpleITK.Image,
) -> imgtools.utils.imageutils.ImageArrayMetadata
Convert a SimpleITK image to a numpy array along with its metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
SimpleITK.Image
|
The SimpleITK image to convert. |
required |
Returns:
Name | Type | Description |
---|---|---|
ImageArrayMetadata |
typing.Tuple[numpy.ndarray, imgtools.utils.imageutils.Array3D, imgtools.utils.imageutils.Array3D, imgtools.utils.imageutils.Array3D]
|
A tuple containing: - The image as a numpy array. - The origin of the image (tuple of floats). - The direction cosines of the image (tuple of floats). - The pixel spacing of the image (tuple of floats). |
Source code in src/imgtools/utils/imageutils.py
physical_points_to_idxs
#
physical_points_to_idxs(
image: SimpleITK.Image,
points: typing.List[numpy.ndarray],
continuous: bool = False,
) -> typing.List[numpy.ndarray]
Convert physical points to image indices based on the reference image's geometry.
This function uses the geometry of a SimpleITK image (origin, spacing, direction) to convert real-world physical coordinates into indices in the image grid. It optionally supports continuous indices for sub-pixel precision.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
SimpleITK.Image
|
The reference SimpleITK image. |
required |
|
typing.List[numpy.ndarray]
|
List of 3D physical points to transform. |
required |
|
bool
|
If True, returns continuous indices; otherwise, returns integer indices. Default is False. |
False
|
Returns:
Type | Description |
---|---|
typing.List[numpy.ndarray]
|
A list of transformed points in image index space, reversed to match library conventions. |
Notes
The following steps occur within the function:
1. A numpy.vectorize
function is defined to apply the transformation
method (physical to index) to each 3D point in the input array.
2. The transformation is applied to each set of points in the list,
reversing the coordinate order to match the library's indexing
convention.