Functional
functional
#
Functions:
Name | Description |
---|---|
clip_intensity |
Clip image intensities to a specified range. |
crop |
Crop an image to a specified window size about a given center. |
resample |
Resample an image to a new spacing with optional transform. |
resize |
Resize an image to a specified size by resampling its coordinates. |
rotate |
Rotate an image around a specified center. |
window_intensity |
Restrict image grey level intensities to a given window and level. |
zoom |
Rescale image, preserving its spatial extent. |
clip_intensity
#
Clip image intensities to a specified range.
Adjusts the input image so that all voxel intensity values lie within the [lower, upper] range. Values below the lower bound are set to lower, while those above the upper bound are set to upper.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
SimpleITK.Image
|
The input intensity image. |
required |
|
float
|
The minimum allowable intensity value. |
required |
|
float
|
The maximum allowable intensity value. |
required |
Returns:
Type | Description |
---|---|
SimpleITK.Image
|
The resulting image with intensity values clipped between lower and upper. |
Source code in src/imgtools/transforms/functional.py
crop
#
crop(
image: SimpleITK.Image,
crop_centre: list[float] | numpy.ndarray,
size: int | list[int] | numpy.ndarray,
) -> SimpleITK.Image
Crop an image to a specified window size about a given center.
This function extracts a sub-region from the input image centered at the provided coordinates. If the cropping window extends beyond the image boundaries, the resulting image will be clipped accordingly. A cropping size of 0 for any dimension retains the original image extent along that axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
SimpleITK.Image
|
The SimpleITK image to crop. |
required |
|
list[float] | numpy.ndarray
|
The center of the cropping window in image coordinates. |
required |
|
int | list[int] | numpy.ndarray
|
The size of the cropping window in pixels. If an int is provided, the same size is applied to all dimensions; a sequence specifies the size along each axis. Use 0 to preserve the original size along a particular dimension. |
required |
Returns:
Type | Description |
---|---|
SimpleITK.Image
|
The cropped image. |
Source code in src/imgtools/transforms/functional.py
resample
#
resample(
image: SimpleITK.Image,
spacing: float | list[float] | numpy.ndarray,
interpolation: str = "linear",
anti_alias: bool = True,
anti_alias_sigma: float | list[float] | None = None,
transform: SimpleITK.Transform | None = None,
output_size: list[float] | None = None,
) -> SimpleITK.Image
Resample an image to a new spacing with optional transform.
Resamples the input image using the specified spacing, computing a new image size to maintain the original spatial extent unless explicitly set via output_size. A transformation can be applied during resampling, and Gaussian smoothing is used for anti-aliasing when downsampling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
SimpleITK.Image
|
The SimpleITK image to be resampled. |
required |
|
float | list[float] | numpy.ndarray
|
The desired spacing for each axis. A single float applies to all dimensions, while a sequence specifies spacing per axis. Use 0 for any axis to retain its original spacing. |
required |
|
str
|
The interpolation method to use. Accepted values are "linear", "nearest", and "bspline". Defaults to "linear". |
'linear'
|
|
bool
|
If True, applies Gaussian smoothing before resampling when downsampling to reduce aliasing artifacts. Defaults to True. |
True
|
|
float | list[float] | None
|
The standard deviation for the Gaussian smoothing kernel. If not provided, it is automatically computed. |
None
|
|
SimpleITK.Transform | None
|
A transformation to apply to the image coordinates during resampling. Defaults to the identity transformation if not specified. |
None
|
|
list[float] | None
|
The desired size of the output image. If omitted, the size is calculated to preserve the entire extent of the input image. |
None
|
Returns:
Type | Description |
---|---|
SimpleITK.Image
|
The resampled image. |
Source code in src/imgtools/transforms/functional.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
resize
#
resize(
image: SimpleITK.Image,
size: int | list[int] | numpy.ndarray,
interpolation: str = "linear",
anti_alias: bool = True,
anti_alias_sigma: float | None = None,
) -> SimpleITK.Image
Resize an image to a specified size by resampling its coordinates.
The function calculates new spacing based on the target size and the original image's dimensions. A value of 0 in the size parameter for any axis preserves the original size for that dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
SimpleITK.Image
|
The image to be resized. |
required |
|
int | list[int] | numpy.ndarray
|
The target image size. If an integer is provided, the same size is applied to all axes. For sequences, a value of 0 for an axis retains the original size in that dimension. |
required |
|
str
|
The interpolation method to use. Valid options are: - "linear" for bi-/trilinear interpolation (default) - "nearest" for nearest-neighbor interpolation - "bspline" for order-3 b-spline interpolation. |
'linear'
|
|
bool
|
If True, apply Gaussian smoothing before resampling when downsampling to reduce aliasing artifacts. |
True
|
|
float | None
|
The standard deviation of the Gaussian kernel used for anti-aliasing. |
None
|
Returns:
Type | Description |
---|---|
SimpleITK.Image
|
The resized image. |
Source code in src/imgtools/transforms/functional.py
rotate
#
rotate(
image: SimpleITK.Image,
rotation_centre: list[int],
angles: list[float],
interpolation: str = "linear",
) -> SimpleITK.Image
Rotate an image around a specified center.
This function applies an Euler rotation to the input image. For 2D images, only the first angle in the provided list is used. For 3D images, all three angles (for the x, y, and z axes, respectively) are applied.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
SimpleITK.Image
|
The image to rotate. |
required |
|
list[int]
|
The center of rotation in image coordinates. If provided as a NumPy array, it is converted to a list. |
required |
|
list[float]
|
A list of rotation angles in radians. For 2D images, only the first value is used. For 3D images, the angles correspond to rotations around the x, y, and z axes. |
required |
|
str
|
The interpolation method for resampling (e.g., "linear", "nearest"). |
'linear'
|
Returns:
Type | Description |
---|---|
SimpleITK.Image
|
The rotated image. |
Source code in src/imgtools/transforms/functional.py
window_intensity
#
Restrict image grey level intensities to a given window and level.
The grey level intensities in the resulting image will fall in the range [level - window / 2, level + window / 2].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
SimpleITK.Image
|
The intensity image to window. |
required |
|
float
|
The width of the intensity window. |
required |
|
float
|
The mid-point of the intensity window. |
required |
Returns:
Type | Description |
---|---|
SimpleITK.Image
|
The windowed intensity image |
Source code in src/imgtools/transforms/functional.py
zoom
#
zoom(
image: SimpleITK.Image,
scale_factor: float | list[float],
interpolation: str = "linear",
anti_alias: bool = True,
anti_alias_sigma: float | None = None,
) -> SimpleITK.Image
Rescale image, preserving its spatial extent.
The image is rescaled using the provided scale factor for each dimension while maintaining its original spatial extent. A single float applies uniformly across all dimensions, whereas a sequence specifies a separate factor for each axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
SimpleITK.Image
|
The image to rescale. |
required |
|
float | list[float]
|
The scaling factor(s) to apply. A float applies to all dimensions; a sequence specifies a factor for each corresponding dimension. |
required |
|
str
|
The interpolation method to use. Options include "linear" (default), "nearest", and "bspline". |
'linear'
|
|
bool
|
Whether to smooth the image using a Gaussian kernel before resampling, which helps reduce aliasing artifacts during downsampling. |
True
|
|
float | None
|
The standard deviation for the Gaussian kernel used in anti-aliasing. |
None
|
Returns:
Type | Description |
---|---|
SimpleITK.Image
|
The rescaled image with the same spatial extent as the original. |