zea.display¶
Display functionality, including scan conversion frustrum conversion, etc.
Functions
|
Convert x, y cartesian coordinates to polar coordinates theta, rho. |
|
Convert a Cartesian image matrix to a polar coordinate representation. |
|
Precompute coordinates for 2d scan conversion from polar coordinates |
|
Precompute coordinates for 3d scan conversion from polar coordinates |
|
Convert coordinates from (rho, theta) space to (X,Z) space using the frustum coordinate conversion. |
|
Convert coordinates from (rho, theta, phi) space to (X,Y,Z) space using the frustum coordinate conversion. |
|
Convert coordinates from (X,Y,Z) space to (rho, theta, phi) space using the frustum coordinate conversion. |
|
Convert coordinates from (X,Z) space to (rho, theta) space using the frustum coordinate conversion. |
|
Convert a Cartesian-format ultrasound image to a polar representation. |
|
map_coordinates using keras.ops or scipy.ndimage when order > 1. |
|
Rotate (x, y) coordinates by a given angle in degrees. |
|
Scan convert image based on number of dimensions. |
|
Perform scan conversion on a 2D ultrasound image from polar coordinates (rho, theta) to Cartesian coordinates (x, z). |
|
Perform scan conversion on a 3D ultrasound image from polar coordinates (rho, theta, phi) to Cartesian coordinates (z, x, y). |
|
Convert image to 8 bit image [0, 255]. |
- zea.display.cart2pol(x, y)[source]¶
Convert x, y cartesian coordinates to polar coordinates theta, rho.
- zea.display.cartesian_to_polar_matrix(cartesian_matrix, fill_value=0.0, polar_shape=None, tip=None, r_max=None, angle=np.float64(0.7853981633974483), interpolation_order=1)[source]¶
Convert a Cartesian image matrix to a polar coordinate representation.
- Parameters:
cartesian_matrix (tensor) – Input 2D image array in Cartesian coordinates.
fill_value (float) – Value to use for points sampled outside the input image.
polar_shape (tuple, optional) – Desired shape of the polar output (rows, cols). Defaults to the shape of the input image.
tip (tuple, optional) – (x, y) coordinates of the origin for the polar transformation (typically the probe tip). Defaults to the center-top of the image.
r_max (float, optional) – Maximum radius to consider in the polar transform. Defaults to the height of the input image.
angle (float) – Total angular field of view (in radians) centered at 0. The polar grid spans from -angle to +angle.
interpolation_order (int) – Order of interpolation to use (0 = nearest-neighbor, 1 = linear, 2+ = spline). Matches the convention of scipy.ndimage.map_coordinates.
- Returns:
The image re-sampled in polar coordinates with shape polar_shape.
- Return type:
polar_matrix (Array)
- zea.display.compute_scan_convert_2d_coordinates(image_shape, rho_range, theta_range, resolution=None, dtype='float32')[source]¶
Precompute coordinates for 2d scan conversion from polar coordinates
- zea.display.compute_scan_convert_3d_coordinates(image_shape, rho_range, theta_range, phi_range, resolution=None, dtype='float32')[source]¶
Precompute coordinates for 3d scan conversion from polar coordinates
- zea.display.frustum_convert_rt2xz(rho, theta)[source]¶
Convert coordinates from (rho, theta) space to (X,Z) space using the frustum coordinate conversion.
Angles are defined in radians.
- Parameters:
rho (ndarray) – Radial coordinates of the points to convert.
theta (ndarray) – Theta coordinates of the points to convert.
- Returns:
X coordinates of the converted points. z (ndarray): Z coordinates of the converted points.
- Return type:
x (ndarray)
- zea.display.frustum_convert_rtp2xyz(rho, theta, phi)[source]¶
Convert coordinates from (rho, theta, phi) space to (X,Y,Z) space using the frustum coordinate conversion.
Angles are defined in radians.
- Parameters:
rho (ndarray) – Radial coordinates of the points to convert.
theta (ndarray) – Theta coordinates of the points to convert.
phi (ndarray) – Phi coordinates of the points to convert.
- Returns:
X coordinates of the converted points. y (ndarray): Y coordinates of the converted points. z (ndarray): Z coordinates of the converted points.
- Return type:
x (ndarray)
- zea.display.frustum_convert_xyz2rtp(x, y, z, theta_limits, phi_limits)[source]¶
Convert coordinates from (X,Y,Z) space to (rho, theta, phi) space using the frustum coordinate conversion.
Angles are defined in radians.
- Parameters:
x (ndarray) – X coordinates of the points to convert.
y (ndarray) – Y coordinates of the points to convert.
z (ndarray) – Z coordinates of the points to convert.
tlimits – Theta and phi limits, respectively, of the original volume. Any point that resides outside of these limits is potentially undefined, and therefore, the radial value for these points is made to be -1.
plimits – Theta and phi limits, respectively, of the original volume. Any point that resides outside of these limits is potentially undefined, and therefore, the radial value for these points is made to be -1.
- Returns:
Radial coordinates of the converted points. theta (ndarray): Theta coordinates of the converted points. phi (ndarray): Phi coordinates of the converted points.
- Return type:
rho (ndarray)
- zea.display.frustum_convert_xz2rt(x, z, theta_limits)[source]¶
Convert coordinates from (X,Z) space to (rho, theta) space using the frustum coordinate conversion.
Angles are defined in radians.
- Parameters:
x (ndarray) – X coordinates of the points to convert.
z (ndarray) – Z coordinates of the points to convert.
theta_limits (list) – Theta limits of the original volume. Any point that resides outside of these limits is potentially undefined, and therefore, the radial value for these points is made to be -1.
- Returns:
Radial coordinates of the converted points. theta (ndarray): Theta coordinates of the converted points.
- Return type:
rho (ndarray)
- zea.display.inverse_scan_convert_2d(cartesian_image, fill_value=0.0, angle=np.float64(0.7853981633974483), output_size=None, interpolation_order=1, find_scan_cone=True)[source]¶
Convert a Cartesian-format ultrasound image to a polar representation.
This function can be used to recover a sector-shaped scan (polar format) from a Cartesian representation of an image. Optionally, it can detect and crop around the scan cone before conversion.
- Parameters:
cartesian_image (tensor) – 2D image array in Cartesian coordinates.
fill_value (float) – Value used to fill regions outside the original image during interpolation.
angle (float) – Angular field of view (in radians) used for the polar transformation. The polar output will span from -angle to +angle.
output_size (tuple, optional) – Shape (rows, cols) of the resulting polar image. If None, the shape of the input image is used.
interpolation_order (int) – Order of interpolation used in resampling (0 = nearest-neighbor, 1 = linear, etc.).
find_scan_cone (bool) – If True, automatically detects and crops around the scan cone in the Cartesian image before polar conversion, ensuring that the scan cone is centered without padding. Can be set to False if the image is already cropped and centered.
- Returns:
2D image in polar coordinates (sector-shaped scan).
- Return type:
polar_image (Array)
- zea.display.map_coordinates(inputs, coordinates, order, fill_mode='constant', fill_value=0)[source]¶
map_coordinates using keras.ops or scipy.ndimage when order > 1.
- zea.display.rotate_coordinates(coords, angle_deg)[source]¶
Rotate (x, y) coordinates by a given angle in degrees.
- zea.display.scan_convert(image, rho_range=None, theta_range=None, phi_range=None, resolution=None, coordinates=None, fill_value=0.0, order=1, with_batch_dim=False)[source]¶
Scan convert image based on number of dimensions.
- zea.display.scan_convert_2d(image, rho_range=None, theta_range=None, resolution=None, coordinates=None, fill_value=0.0, order=1, **kwargs)[source]¶
Perform scan conversion on a 2D ultrasound image from polar coordinates (rho, theta) to Cartesian coordinates (x, z).
- Parameters:
image (ndarray) – The input 2D ultrasound image in polar coordinates. Has dimensions (n_rho, n_theta) with optional batch.
rho_range (tuple) – A tuple specifying the range of rho values (min_rho, max_rho). Defined in mm.
theta_range (tuple) – A tuple specifying the range of theta values (min_theta, max_theta). Defined in radians.
resolution (float, optional) – The resolution for the Cartesian grid. If None, it is calculated based on the input image. In mm / pixel.
coordinates (ndarray, optional) – Precomputed coordinates for scan conversion. If provided, it will be used instead of computing new coordinates based on the input image shape and ranges.
fill_value (float, optional) – The value to fill in for coordinates outside the input image ranges. Defaults to 0.0. When set to NaN, no interpolation at the edges will happen.
order (int, optional) – The order of the spline interpolation. Defaults to 1.
- Returns:
- The scan-converted 2D ultrasound image in Cartesian coordinates.
Has dimensions (grid_size_z, grid_size_x). Coordinates outside the input image ranges are filled with NaNs.
- parameters (dict): A dictionary containing information about the scan conversion.
Contains the resolution, x, and z limits, rho and theta ranges.
- Return type:
ndarray
Note
Polar grid is inferred from the input image shape and the supplied rho and theta ranges. Cartesian grid is computed based on polar grid with resolutions specified by resolution parameter.
- zea.display.scan_convert_3d(image, rho_range=None, theta_range=None, phi_range=None, resolution=None, coordinates=None, fill_value=0.0, order=1)[source]¶
Perform scan conversion on a 3D ultrasound image from polar coordinates (rho, theta, phi) to Cartesian coordinates (z, x, y).
- Parameters:
image (ndarray) – The input 3D ultrasound image in polar coordinates. Has dimensions (n_rho, n_theta, n_phi) with optional batch.
rho_range (tuple) – A tuple specifying the range of rho values (min_rho, max_rho). Defined in mm.
theta_range (tuple) – A tuple specifying the range of theta values (min_theta, max_theta). Defined in radians.
phi_range (tuple) – A tuple specifying the range of phi values (min_phi, max_phi). Defined in radians.
resolution (float, optional) – The resolution for the Cartesian grid. If None, it is calculated based on the input image. In mm / pixel.
coodinates (ndarray, optional) – Precomputed coordinates for scan conversion. If provided, it will be used instead of computing new coordinates based on the input image shape and ranges.
fill_value (float, optional) – The value to fill in for coordinates outside the input image ranges. Defaults to 0.0. When set to NaN, no interpolation at the edges will happen.
order (int, optional) – The order of the spline interpolation. Defaults to 1.
- Returns:
- The scan-converted 3D ultrasound image in Cartesian coordinates.
Has dimensions (grid_size_z, grid_size_x, n_y). Coordinates outside the input image ranges are filled with NaNs.
- parameters (dict): A dictionary containing information about the scan conversion.
Contains the resolution, x, y, and z limits, rho, theta, and phi ranges.
- Return type:
ndarray
Note
Polar grid is inferred from the input image shape and the supplied rho, theta and phi ranges. Cartesian grid is computed based on polar grid with resolutions specified by resolution parameter.
- zea.display.to_8bit(image, dynamic_range=None, pillow=True)[source]¶
Convert image to 8 bit image [0, 255]. Clip between dynamic range.
- Parameters:
image (ndarray) – Input image(s). Should be in between dynamic range.
dynamic_range (tuple, optional) – Dynamic range of input image(s).
pillow (bool, optional) – Whether to return PIL image. Defaults to True.
- Returns:
Output 8 bit image(s) [0, 255].
- Return type:
image (ndarray)