zea.displayΒΆ
Display functionality, including scan conversion frustrum conversion, etc.
Functions
|
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 frustum coordinates. |
|
Deprecated, use |
|
Deprecated, use |
|
Deprecated, use |
|
Deprecated, use |
|
Convert frustum coordinates (radius, polar angle, elevation angle) to (x, y, z). |
|
Convert polar coordinates (radius, polar angle) to (x, z): the 2D case of |
|
Match the histogram of an image to a reference image, for fair visual comparison. |
|
Convert a Cartesian-format ultrasound image to a polar representation. |
|
map_coordinates using keras.ops or scipy.ndimage when order > 1. |
|
Overlay segmentation masks on top of an image using PIL. |
|
(radius, polar angle) sampling grid that pins a polar cone's apex at pixel |
|
Resample a polar image onto a fixed Cartesian canvas with the apex at a chosen pixel. |
|
Scan convert image based on number of dimensions. |
|
Perform scan conversion on a 2D ultrasound image from polar coordinates (radius, polar angle) to Cartesian coordinates (x, z). |
|
Perform scan conversion on a 3D ultrasound image from frustum coordinates (radius, polar angle, elevation angle) to Cartesian coordinates (z, x, y). |
|
Convert image to 8 bit image [0, 255]. |
|
Convert (x, y, z) to frustum coordinates (radius, polar angle, elevation angle), the inverse of |
|
Convert (x, z) to polar coordinates (radius, polar angle), the inverse of |
- zea.display.cartesian_to_polar_matrix(cartesian_matrix, fill_value=0.0, polar_shape=None, tip=None, r_max=None, theta_range=None, interpolation_order=1, *, polar_limits=None)[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.
polar_limits (tuple, optional) β Polar angle
atan(x / z)[rad] of the first and last column of the polar output, positive toward +x (increasing column index of the Cartesian image), as inscan_convert_2d(). Unequal magnitudes describe an asymmetric cone. Defaults to (-45, 45) degrees.interpolation_order (int) β Order of interpolation to use (0 = nearest-neighbor, 1 = linear, 2+ = spline). Matches the convention of scipy.ndimage.map_coordinates.
theta_range (tuple, optional) β Deprecated, use
polar_limits. It measured angles toward -x, sotheta_range=(a, b)ispolar_limits=(-b, -a).
- Returns:
- The image re-sampled in polar coordinates with shape
polar_shape.
- coordinates (Array): The Cartesian coordinates corresponding to each pixel in
the polar output.
- Return type:
polar_matrix (Array)
- zea.display.compute_scan_convert_2d_coordinates(image_shape, rlims=None, polar_limits=None, resolution=None, dtype='float32', distance_to_apex=None, *, grid_apex=None, extent=None, rho_range=None, theta_range=None)[source]ΒΆ
Precompute coordinates for 2d scan conversion from polar coordinates.
The polar image has one row per radius and one column per polar angle. The radius is measured from
grid_apex, the point the polar grid fans out from (seezea.Parameters.grid_apex), and the polar angle isatan(x / z), from the z-axis in the x-z plane, positive towards +x. The returned coordinates index the polar image, so they live in that apex frame;grid_apexonly moves the output window into the transducer frame, where the reportedx_limandz_limare given (matchingzea.Parameters.extent).- Parameters:
image_shape (tuple) β Shape of the polar image,
(..., n_rho, n_theta).rlims (
Optional[Tuple[float,float]]) β Radius of the first and last row, measured fromgrid_apex.polar_limits (
Optional[Tuple[float,float]]) β Angle of the first and last column [rad].resolution (
Optional[float]) β Output pixel size. Derived from the polar image when not given.dtype (
str) β Dtype of the coordinates. Defaults to"float32".grid_apex (array-like, optional) β The apex
(x, y, z)in the transducer frame. Defaults to the origin, which makes the two frames coincide.extent (array-like, optional) β The output window in the transducer frame, as
zea.Parameters.extentgives it:(xmin, xmax, ..., zmin, zmax). Pixels outside the polar image are filled. Defaults to the bounding box of the polar image.distance_to_apex (float, optional) β Deprecated, use
grid_apex=(0, 0, -distance_to_apex).rho_range (tuple, optional) β Deprecated, use
rlims.theta_range (tuple, optional) β Deprecated, use
polar_limits.
- Returns:
The sampling coordinates and a dict with
resolution,x_lim,z_lim,rlims,polar_limits,drandd_polar(the radius and angle steps between rows and columns).- Return type:
tuple
- zea.display.compute_scan_convert_3d_coordinates(image_shape, rlims=None, polar_limits=None, elevation_limits=None, resolution=None, dtype='float32', *, rho_range=None, theta_range=None, phi_range=None)[source]ΒΆ
Precompute coordinates for 3d scan conversion from frustum coordinates.
The volume is indexed by radius, the polar angle
atan(x / z)and the elevation angleatan(y / z)(seefrustum_to_xyz()). Both angles are projections onto the x-z and y-z planes, not the sphericalpolar_anglesandazimuth_anglesof the transmits; at elevation 0 the volume reduces to the 2D sector ofscan_convert_2d().- Parameters:
image_shape (tuple) β Shape of the volume,
(..., n_radius, n_polar, n_elevation).rlims (
Optional[Tuple[float,float]]) β Radius of the first and last sample along the radius axis.polar_limits (
Optional[Tuple[float,float]]) β Polar angleatan(x / z)of the first and last sample along the polar axis [rad], ascending.elevation_limits (
Optional[Tuple[float,float]]) β Elevation angleatan(y / z)of the first and last sample along the elevation axis [rad], ascending.resolution (
Optional[float]) β Output voxel size. Derived from the volume when not given.dtype (
str) β Dtype of the coordinates. Defaults to"float32".rho_range (tuple, optional) β Deprecated, use
rlims.theta_range (tuple, optional) β Deprecated, use
polar_limits.phi_range (tuple, optional) β Deprecated, use
elevation_limits.
- zea.display.frustum_convert_rt2xz(rho, theta)[source]ΒΆ
Deprecated, use
frustum_to_xz()(thetais itspolarangle).
- zea.display.frustum_convert_rtp2xyz(rho, theta, phi)[source]ΒΆ
Deprecated, use
frustum_to_xyz()(thetais itspolarandphiitselevationangle).
- zea.display.frustum_convert_xyz2rtp(x, y, z, theta_limits, phi_limits)[source]ΒΆ
Deprecated, use
xyz_to_frustum()(theta_limitsis itspolar_limitsandphi_limitsitselevation_limits).
- zea.display.frustum_convert_xz2rt(x, z, theta_limits)[source]ΒΆ
Deprecated, use
xz_to_frustum()(theta_limitsis itspolar_limits).
- zea.display.frustum_to_xyz(radius, polar, elevation)[source]ΒΆ
Convert frustum coordinates (radius, polar angle, elevation angle) to (x, y, z).
The polar angle
atan(x / z)and the elevation angleatan(y / z)are projections onto the x-z and y-z planes, not the sphericalpolar_anglesandazimuth_anglesof the transmits (see Angle and radius names). Angles are defined in radians.- Parameters:
radius (ndarray) β Radial coordinates of the points to convert.
polar (ndarray) β Polar angles
atan(x / z)of the points to convert.elevation (ndarray) β Elevation angles
atan(y / z)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_to_xz(radius, polar)[source]ΒΆ
Convert polar coordinates (radius, polar angle) to (x, z): the 2D case of
frustum_to_xyz(), at elevation 0.The polar angle
atan(x / z)is signed, positive toward +x. Angles are defined in radians.- Parameters:
radius (ndarray) β Radial coordinates of the points to convert.
polar (ndarray) β Polar angles
atan(x / z)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.histogram_match(image, reference, mode='full', n_bins=256, roi=None, allow_unequal_shapes=False, exclude_below=-300.0)[source]ΒΆ
Match the histogram of an image to a reference image, for fair visual comparison.
Image formation methods apply different dynamic range transformations, which biases visual as well as quantitative comparison. Matching the histogram of an image to a reference (typically a conventional B-mode image) puts the two on a common scale.
Reference
N. Bottenus, B. C. Byram, and D. Hyun, βHistogram Matching for Visual Ultrasound Image Comparison,β IEEE Transactions on Ultrasonics, Ferroelectrics, and Frequency Control, vol. 68, no. 5, pp. 1487β1495, 2021. doi.org/10.1109/TUFFC.2020.3035965
Their MATLAB implementation, referred to above as the reference implementation: https://github.com/nbottenus/histogram_matching/blob/main/histmatch.m
- Parameters:
image (ndarray) β Image to transform, typically log-compressed (dB).
reference (ndarray) β Image to match to. Has to be of the shape of
image, unlessallow_unequal_shapessays otherwise.mode (
str) βClass of transform to match with. Defaults to
"full"."partial": affine match (Sec. III.A), the scale and offset that match mean and variance. It leaves the shape of the imageβs own distribution intact, so pick it when that shape is the thing under comparison, when the fitted region contains structure rather than plain speckle, or when the CNR must survive the matching."full": any monotone mapping (Sec. III.B), the one that carries the histogram of the image onto that of the reference, estimated onn_binsbins. It matches the shape of the distribution too, hence undoes non-linear compression, so pick it to compare methods whose transformations differ in more than scale and offset, or are unknown (βblack boxβ images, Sec. III.C.2). Together with a speckleroi, the paperβs expected common use (Sec. V).
n_bins (
Union[int,str]) β Number of bins the mapping of a"full"match is estimated on; ignored by"partial". Defaults to 256, the number of bins used in the paper, which it found enough for consistent results. Pass"all"for one bin per fitted pixel, the limit of the binning process (Sec. III.C.1): it reproduces the reference distribution down to its outliers and tails, which replicates them in the matched image. This is what skimage.exposure.match_histograms does.roi (ndarray, optional) β Boolean mask, of the shape of both images, selecting a homogeneous speckle region (Sec. III.C.3, the paperβs expected common use). The mapping is fit inside the mask and applied to the whole image, extended linearly outside the fitted range. Defaults to None (fit on the whole image).
allow_unequal_shapes (
bool) β Whetherreferencemay be of a shape other than that ofimage. Only the two distributions are compared, so a match is well defined either way, but images of different shapes are more often a mistake (a stray transpose, the wrong frame of a sequence) than an intent. Defaults to False. Pass True to match against a reference deliberately not of the shape of the image, e.g. a region cut out of a larger acquisition. Anroihas to index both images regardless, so it cannot be combined with unequal shapes.exclude_below (
Optional[float]) β Value at or below which a pixel of either image is kept out of the fit and the transform. Defaults to -300.0, which catches zeaβslog(0)sentinel and nothing a log-compressed B-mode measures. Pass None to exclude nothing but the non-finite pixels.
- Returns:
Transformed image (float64), unclipped: clipping to a display range is left to the caller (to_8bit, or
vmin/vmax).- Return type:
ndarray
Note
Which image is matched to which is a choice (Sec. V): matching to B-mode is natural for a reader used to B-mode, but features outside its dynamic range are lost in the process, and matching in the other direction then shows them off better.
Example
>>> import numpy as np >>> from zea.display import histogram_match >>> rng = np.random.default_rng(0) >>> image = 20 * np.log10(rng.rayleigh(0.1, (64, 64))) >>> reference = 20 * np.log10(rng.rayleigh(1.0, (64, 64))) >>> round(image.mean() - reference.mean()) # the image is 20 dB darker -20 >>> matched = histogram_match(image, reference) >>> round(matched.mean() - reference.mean()) 0
- zea.display.inverse_scan_convert_2d(cartesian_image, fill_value=0.0, theta_range=None, output_size=None, interpolation_order=1, find_scan_cone=True, image_range=None, *, polar_limits=None)[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 of type float.
fill_value (float) β Value used to fill regions outside the original image during interpolation.
polar_limits (tuple, optional) β Polar angle
atan(x / z)[rad] of the first and last column of the polar image, positive toward +x, as inscan_convert_2d(). Unequal magnitudes describe an asymmetric cone. Defaults to (-45, 45) degrees.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.
image_range (
tuple|None) β Tuple (vmin, vmax) for display scaling when detecting the scan cone.theta_range (tuple, optional) β Deprecated, use
polar_limits. It measured angles toward -x, sotheta_range=(a, b)ispolar_limits=(-b, -a).
- 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.overlay_masks(image, masks, alpha=0.5, colors=None)[source]ΒΆ
Overlay segmentation masks on top of an image using PIL.
- Parameters:
image (PIL.Image or ndarray) β Base image. If grayscale, it is converted to RGB. If ndarray, it is converted to a PIL Image first.
masks (list of PIL.Image or ndarray) β Segmentation masks to overlay. Each mask should be an 8-bit single-channel image where non-zero pixels indicate the masked region.
alpha (
float) β Opacity of the mask overlays in [0, 1]. Defaults to 0.5.colors (list of tuple, optional) β RGB colors for each mask. If None, a default palette is used. If provided, must contain at least as many entries as masks (extra entries are ignored).
- Returns:
RGB image with masks overlaid.
- Return type:
PIL.Image
- zea.display.polar_to_cartesian_coordinates(cartesian_shape, n_r, n_polar, tip=None, r_max=None, theta_range=None, pitch=1.0, dtype='float32', *, polar_limits=None)[source]ΒΆ
(radius, polar angle) sampling grid that pins a polar coneβs apex at pixel
tip.Shared core of
polar_to_cartesian_matrix(): builds the fractional index grid that resamples an(n_r, n_polar)polar image onto acartesian_shapecanvas, with the apex at pixeltipandpitchunits per pixel. Pass the result ascoordinatestoscan_convert_2d()(or theScanConvertoperation) to run the same resampling inside a pipeline. Unlikecompute_scan_convert_2d_coordinates(), this uses thearctan2mapping in_polar_sampling_coordinates(), so it covers a full circle rather than only a narrow (polar angle withinpi/2) sector.- Parameters:
cartesian_shape (
Tuple[int,int]) β Output(rows, cols)=(n_z, n_x).n_r (
int) β Radial samples (rows) of the polar image the indices address.n_polar (
int) β Angular samples (columns) of the polar image the indices address.tip (
Optional[Tuple[float,float]]) β(col, row)pixel location of the cone apex in the output. Defaults to the centre-top(cols / 2, 0).r_max (
Optional[float]) β Radius spanned by the polar image, in the same units aspitch(pixels by default). Defaults torows.polar_limits (
Optional[Tuple[float,float]]) β Polar angleatan(x / z)[rad] of the first and last column of the polar image, positive toward +x (increasing column index of the output). Defaults to (-45, 45) degrees.pitch (
float) β Output units per pixel (radial units ofr_max). Defaults to 1.0, i.e.tipandr_maxare in pixels.dtype (
str) β Compute dtype for the axes. Defaults to"float32".theta_range (tuple, optional) β Deprecated, use
polar_limits. It measured angles toward -x, sotheta_range=(a, b)ispolar_limits=(-a, -b).
- Returns:
(2, cols, rows)stack of[rho_idx, theta_idx]sampling indices.- Return type:
coords (Array)
- zea.display.polar_to_cartesian_matrix(polar_matrix, cartesian_shape, tip=None, r_max=None, theta_range=None, pitch=1.0, fill_value=0.0, order=1, *, polar_limits=None)[source]ΒΆ
Resample a polar image onto a fixed Cartesian canvas with the apex at a chosen pixel.
Faithful inverse of
cartesian_to_polar_matrix(). Wherescan_convert_2d()fits the cone bounding box into the output (losing absolute position and scale), this pins the cone apex at pixeltipon a canvas of shapecartesian_shapeand samples atpitchunits per pixel, so a forward/inverse round-trip reproduces the original frame. Both share the_polar_sampling_coordinates()core; they differ only in how the output grid is built.- Parameters:
polar_matrix (tensor) β Input polar image of shape
(n_r, n_polar), float type.cartesian_shape (
Tuple[int,int]) β Output(rows, cols)=(n_z, n_x).tip (
Optional[Tuple[float,float]]) β(col, row)pixel location of the cone apex in the output. Defaults to the centre-top(cols / 2, 0).r_max (
Optional[float]) β Radius spanned by the polar image, in the same units aspitch(pixels by default). Defaults torows.polar_limits (
Optional[Tuple[float,float]]) β Polar angleatan(x / z)[rad] of the first and last column ofpolar_matrix, positive toward +x (increasing column index of the output). Pass thepolar_limitsgiven tocartesian_to_polar_matrix()to invert it. Defaults to (-45, 45) degrees.pitch (
float) β Output units per pixel (radial units ofr_max). Defaults to 1.0, i.e.tipandr_maxare in pixels.fill_value (
float) β Value for pixels outside the polar domain.order (
int) β Spline interpolation order. Defaults to 1.theta_range (tuple, optional) β Deprecated, use
polar_limits. It measured angles toward -x, sotheta_range=(a, b)ispolar_limits=(-a, -b).
- Returns:
- The polar image resampled onto the Cartesian canvas, with
shape
cartesian_shape.
- Return type:
cartesian_matrix (Array)
- zea.display.scan_convert(image, rlims=None, polar_limits=None, elevation_limits=None, resolution=None, coordinates=None, fill_value=0.0, order=1, with_batch_dim=False, distance_to_apex=None, *, grid_apex=None, extent=None, rho_range=None, theta_range=None, phi_range=None)[source]ΒΆ
Scan convert image based on number of dimensions.
A 2D image goes to
scan_convert_2d()withrlimsandpolar_limits; a 3D volume goes toscan_convert_3d(), which addselevation_limits. The polar angleatan(x / z)means the same in both, so a 3D frustum extends the 2D sector in elevation.grid_apexandextentapply to 2D images only.rho_range,theta_rangeandphi_rangeare deprecated aliases ofrlims,polar_limitsandelevation_limits.
- zea.display.scan_convert_2d(image, rlims=None, polar_limits=None, resolution=None, coordinates=None, fill_value=0.0, order=1, distance_to_apex=None, *, grid_apex=None, extent=None, rho_range=None, theta_range=None, **kwargs)[source]ΒΆ
Perform scan conversion on a 2D ultrasound image from polar coordinates (radius, polar angle) to Cartesian coordinates (x, z).
- Parameters:
image (ndarray) β The input 2D ultrasound image in polar coordinates. Has dimensions (n_radius, n_polar) with optional batch.
rlims (
Optional[Tuple[float,float]]) β Radius(rho_min, rho_max)of the first and last row, measured fromgrid_apex. In the same unit as the output grid.polar_limits (
Optional[Tuple[float,float]]) β Polar angleatan(x / z)of the first and last column [rad], from the z-axis in the x-z plane, positive towards +x.resolution (
Optional[float]) β The resolution for the Cartesian grid. If None, it is calculated based on the input image. In units ofrlimsper pixel.coordinates (
Optional[ndarray]) β 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) β 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) β The order of the spline interpolation. Defaults to 1.grid_apex (array-like, optional) β The point
(x, y, z)that the radius is measured from, in the transducer frame (seezea.Parameters.grid_apex). Moves the reportedx_limandz_liminto the transducer frame. Defaults to the origin.extent (array-like, optional) β Output window in the transducer frame,
(xmin, xmax, ..., zmin, zmax)aszea.Parameters.extentgives it. Defaults to the bounding box of the polar image.distance_to_apex (float, optional) β Deprecated, use
grid_apex=(0, 0, -distance_to_apex).rho_range (tuple, optional) β Deprecated, use
rlims.theta_range (tuple, optional) β Deprecated, use
polar_limits.
- 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,
rlimsandpolar_limits.
- Return type:
ndarray
Note
Polar grid is inferred from the input image shape and the supplied
rlimsandpolar_limits. Cartesian grid is computed based on polar grid with resolutions specified by resolution parameter.
- zea.display.scan_convert_3d(image, rlims=None, polar_limits=None, elevation_limits=None, resolution=None, coordinates=None, fill_value=0.0, order=1, *, rho_range=None, theta_range=None, phi_range=None)[source]ΒΆ
Perform scan conversion on a 3D ultrasound image from frustum coordinates (radius, polar angle, elevation angle) to Cartesian coordinates (z, x, y).
The polar angle
atan(x / z)and the elevation angleatan(y / z)(seefrustum_to_xyz()) are projections onto the x-z and y-z planes, not the sphericalpolar_anglesandazimuth_anglesof the transmits.- Parameters:
image (ndarray) β The input 3D ultrasound image in frustum coordinates. Has dimensions (n_radius, n_polar, n_elevation) with optional batch.
rlims (
Optional[Tuple[float,float]]) β Radius(rho_min, rho_max)of the first and last sample.polar_limits (
Optional[Tuple[float,float]]) β Polar angleatan(x / z)of the first and last sample [rad].elevation_limits (
Optional[Tuple[float,float]]) β Elevation angleatan(y / z)of the first and last sample [rad].resolution (
Optional[float]) β The resolution for the Cartesian grid. If None, it is calculated based on the input image. In units ofrlimsper 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) β 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) β The order of the spline interpolation. Defaults to 1.rho_range (tuple, optional) β Deprecated, use
rlims.theta_range (tuple, optional) β Deprecated, use
polar_limits.phi_range (tuple, optional) β Deprecated, use
elevation_limits.
- 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,
rlims,polar_limitsandelevation_limits.
- Return type:
ndarray
Note
Frustum grid is inferred from the input image shape and the supplied limits. Cartesian grid is computed based on the frustum 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 (
Optional[tuple]) β Dynamic range of input image(s).pillow (
bool) β Whether to return PIL image. Defaults to True.
- Returns:
Output 8 bit image(s) [0, 255].
- Return type:
image (ndarray)
Note
If dynamic_range is None, it is assumed that the input image is already in the range [-60, 0] dB, which is a common range for ultrasound images.
Note
NaN values in the input image are replaced with the minimum value of the dynamic range before scaling, which ensures that they are represented as black (0) in the output image. +/- inf values are replaced with the min and max values of the dynamic range.
Example
>>> import numpy as np >>> import zea >>> file_path = ( ... "hf://zeahub/camus-sample/val/patient0401/patient0401_4CH_half_sequence.hdf5" ... ) >>> with zea.File(file_path, mode="r") as file: ... data = file.data.image.values[0] >>> image, _ = zea.display.scan_convert( ... data, ... rlims=(0, 1), ... polar_limits=(-0.78, 0.78), ... fill_value=np.nan, ... ) >>> image = zea.display.to_8bit(image, dynamic_range=(-60, 0)) >>> image.save("image.png")
- zea.display.xyz_to_frustum(x, y, z, polar_limits, elevation_limits)[source]ΒΆ
Convert (x, y, z) to frustum coordinates (radius, polar angle, elevation angle), the inverse of
frustum_to_xyz().The polar angle
atan(x / z)and the elevation angleatan(y / z)are projections onto the x-z and y-z planes (see Angle and radius names). 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.
polar_limits β Polar and elevation angle 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.
elevation_limits β Polar and elevation angle 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. polar (ndarray): Polar angles
atan(x / z)of the converted points. elevation (ndarray): Elevation anglesatan(y / z)of the converted points.- Return type:
radius (ndarray)
- zea.display.xz_to_frustum(x, z, polar_limits)[source]ΒΆ
Convert (x, z) to polar coordinates (radius, polar angle), the inverse of
frustum_to_xz().The polar angle
atan(x / z)is signed, positive toward +x. Angles are defined in radians.- Parameters:
x (ndarray) β X coordinates of the points to convert.
z (ndarray) β Z coordinates of the points to convert.
polar_limits (list) β Polar angle limits of the original image. 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. polar (ndarray): Polar angles
atan(x / z)of the converted points.- Return type:
radius (ndarray)