ultrasound_metrics.metrics.fwhm#

Full-Width at Half-Maximum (FWHM) measurement for point targets in ultrasound images.

Attributes#

Functions#

calculate_fwhm_from_2D_gaussian_fit(...)

Calculate FWHM from 2D Gaussian fit.

calculate_fwhm_from_var(...)

Calculate FWHM from variance.

calculate_linear_interpolation(→ float)

Calculate linear interpolation between two points.

calculate_var_from_fwhm(...)

Calculate variance from FWHM.

compute_fwhm(→ tuple[Optional[float], Ellipsis])

Compute the full-width half-max of a point target.

convert_fwhm_to_input_units(...)

Convert FWHM from pixels to physical units.

crop_image_around_max(...)

Crop image around maximum value.

find_max_idx_within_expected_target_radius(...)

Find maximum index within expected target radius.

fit_2d_gaussian(→ numpy.typing.NDArray[numpy.floating])

Fit a 2D Gaussian to the image and return the parameters.

gaussian_2d(→ numpy.typing.NDArray[numpy.floating])

2D Gaussian function.

get_subscript_idx_of_target_max_within_roi(...)

Get subscript index of maximum value within ROI.

measure_fwhm_of_target(...)

Measure FWHM across all dimensions of the target.

measure_half_width_half_max(→ float)

Measure half-width at half-maximum of a 1D array.

measure_sub_pixel_fwhm(→ float)

Measure the sub-pixel FWHM using linear interpolation.

reduce_image_to_1D_at_point(...)

Reduce image to 1D at specified point.

reduce_image_to_only_measurement_dimensions(...)

Reduce image to only specified measurement dimensions.

reorder_measured_dims_into_original_shape(...)

Reorder the measured FWHM values into the original shape.

set_default_measurement_dims(...)

Set default measurement dimensions based on image shape.

Module Contents#

ultrasound_metrics.metrics.fwhm.calculate_fwhm_from_2D_gaussian_fit(
img: numpy.typing.NDArray[numpy.floating],
img_max_idx: tuple[int, Ellipsis],
fwhm: numpy.typing.NDArray[numpy.floating],
) numpy.typing.NDArray[numpy.floating][source]#

Calculate FWHM from 2D Gaussian fit.

Parameters:
  • img – Input 2D image array.

  • img_max_idx – Index of maximum value in the image.

  • fwhm – Initial FWHM estimate.

Returns:

FWHM values from the Gaussian fit.

Return type:

ndarray

ultrasound_metrics.metrics.fwhm.calculate_fwhm_from_var(
var: numpy.typing.NDArray[numpy.floating],
) numpy.typing.NDArray[numpy.floating][source]#

Calculate FWHM from variance.

Parameters:

var – Variance values.

Returns:

FWHM values.

Return type:

ndarray

ultrasound_metrics.metrics.fwhm.calculate_linear_interpolation(
a: float,
b: float,
a_idx: int,
b_idx: int,
interp_val: float,
) float[source]#

Calculate linear interpolation between two points.

Parameters:
  • a – Value at first point.

  • b – Value at second point.

  • a_idx – Index of first point.

  • b_idx – Index of second point.

  • interp_val – Value to interpolate to.

Returns:

Interpolated index value.

Return type:

float

ultrasound_metrics.metrics.fwhm.calculate_var_from_fwhm(
fwhm: numpy.typing.NDArray[numpy.floating],
) numpy.typing.NDArray[numpy.floating][source]#

Calculate variance from FWHM.

Parameters:

fwhm – Full-width at half-maximum values.

Returns:

Variance values.

Return type:

ndarray

ultrasound_metrics.metrics.fwhm.compute_fwhm(
img: numpy.typing.NDArray[numpy.floating],
roi_indices: numpy.typing.NDArray[numpy.integer] | None = None,
dims_to_measure: numpy.typing.NDArray[numpy.integer] | None = None,
target_radius: int | None = None,
bf_grid_spacing: numpy.typing.NDArray[numpy.floating] | None = None,
img_save_filename: str | None = None,
) tuple[float | None, Ellipsis][source]#

Compute the full-width half-max of a point target.

Parameters:
  • img – The input image.

  • roi_indices – Region of interest in the form of array indices.

  • dims_to_measure – List of dimensions across which to measure the FWHM. If None, then the default space dimensions of the bmode image are used (dimensions [1,2,3]). If any of these dimensions are singleton, then they are excluded from consideration.

  • target_radius – Expected radius of the target used to find max point around the max detected within the ROI. This is used in case the target is registered but the position of the max value is not located within the ROI. If None, then then no search for the max value outside the roi is performed.

  • bf_grid_spacing – The beamforming grid spacing in shape and dimension ordering consistent with the img parameter. If None, then the FWHM is returned in units of pixels.

  • img_save_filename – Optional filename to save diagnostic image.

Returns:

The full-width half-max of the point target over all input and non-singleton dimensions.

Return type:

tuple

ultrasound_metrics.metrics.fwhm.convert_fwhm_to_input_units(
fwhm: numpy.typing.NDArray[numpy.floating],
bf_grid_spacing: numpy.typing.NDArray[numpy.floating],
) numpy.typing.NDArray[numpy.floating][source]#

Convert FWHM from pixels to physical units.

Parameters:
  • fwhm – FWHM values in pixels.

  • bf_grid_spacing – Grid spacing for unit conversion.

Returns:

FWHM values in physical units.

Return type:

ndarray

ultrasound_metrics.metrics.fwhm.crop_image_around_max(
img: numpy.typing.NDArray[numpy.floating],
img_max_idx: tuple[int, Ellipsis],
fwhm: numpy.typing.NDArray[numpy.floating],
) tuple[numpy.typing.NDArray[numpy.floating], tuple[int, int]][source]#

Crop image around maximum value.

Parameters:
  • img – Input image array.

  • img_max_idx – Index of maximum value in the image.

  • fwhm – FWHM values for determining crop size.

Returns:

Cropped image and new maximum index within the cropped image.

Return type:

tuple

ultrasound_metrics.metrics.fwhm.find_max_idx_within_expected_target_radius(
img: numpy.typing.NDArray[numpy.floating],
img_max_idx: tuple[int, Ellipsis],
radius: int,
) tuple[int, Ellipsis][source]#

Find maximum index within expected target radius.

Parameters:
  • img – Input image array.

  • img_max_idx – Initial maximum index.

  • radius – Search radius around the initial maximum.

Returns:

Index of maximum value within the specified radius.

Return type:

tuple

ultrasound_metrics.metrics.fwhm.fit_2d_gaussian(
img: numpy.typing.NDArray[numpy.floating],
initial_guess: tuple[float, Ellipsis],
) numpy.typing.NDArray[numpy.floating][source]#

Fit a 2D Gaussian to the image and return the parameters.

Parameters:
  • img – Input 2D image array.

  • initial_guess – Initial parameter guess for the Gaussian fit.

Returns:

Fitted Gaussian parameters.

Return type:

ndarray

ultrasound_metrics.metrics.fwhm.gaussian_2d(
xy: tuple[numpy.typing.NDArray[numpy.floating], numpy.typing.NDArray[numpy.floating]],
amplitude: float,
xo: float,
yo: float,
sigma_x: float,
sigma_y: float,
theta: float,
offset: float,
) numpy.typing.NDArray[numpy.floating][source]#

2D Gaussian function.

Parameters:
  • xy – Tuple of (x, y) coordinate arrays.

  • amplitude – Amplitude of the Gaussian.

  • xo – X-coordinate of the center.

  • yo – Y-coordinate of the center.

  • sigma_x – Standard deviation in x-direction.

  • sigma_y – Standard deviation in y-direction.

  • theta – Rotation angle.

  • offset – Vertical offset.

Returns:

Flattened Gaussian values.

Return type:

ndarray

ultrasound_metrics.metrics.fwhm.get_subscript_idx_of_target_max_within_roi(
img: numpy.typing.NDArray[numpy.floating],
roi_indices: numpy.typing.NDArray[numpy.integer],
) tuple[int, Ellipsis][source]#

Get subscript index of maximum value within ROI.

Parameters:
  • img – Input image array.

  • roi_indices – Indices defining the region of interest.

Returns:

Subscript index of the maximum value within the ROI.

Return type:

tuple

ultrasound_metrics.metrics.fwhm.measure_fwhm_of_target(
img: numpy.typing.NDArray[numpy.floating],
img_max_idx: tuple[int, Ellipsis],
) numpy.typing.NDArray[numpy.floating][source]#

Measure FWHM across all dimensions of the target.

Parameters:
  • img – Input image array.

  • img_max_idx – Index of the maximum value in the image.

Returns:

FWHM for each dimension.

Return type:

ndarray

ultrasound_metrics.metrics.fwhm.measure_half_width_half_max(
pixel_array: numpy.typing.NDArray[numpy.floating],
max_val: float,
use_interp: bool,
) float[source]#

Measure half-width at half-maximum of a 1D array.

Parameters:
  • pixel_array – 1D pixel array.

  • max_val – Maximum value in the array.

  • use_interp – Whether to use linear interpolation for sub-pixel precision.

Returns:

Half-width at half-maximum.

Return type:

float

ultrasound_metrics.metrics.fwhm.measure_sub_pixel_fwhm(
im_line: numpy.typing.NDArray[numpy.floating],
max_idx: int,
max_val: float,
use_interp: bool = True,
) float[source]#

Measure the sub-pixel FWHM using linear interpolation.

Parameters:
  • im_line – The 1-D orthogonal line across the target.

  • max_idx – The index of the maximum position in the ROI.

  • max_val – The value of the maximum position in the ROI.

  • use_interp – Whether to use linear interpolation to obtain sub-pixel precision.

Returns:

The sub-pixel FWHM.

Return type:

float

ultrasound_metrics.metrics.fwhm.reduce_image_to_1D_at_point(
img: numpy.typing.NDArray[numpy.floating],
point: tuple[int, Ellipsis],
keep_dim: int,
) numpy.typing.NDArray[numpy.floating][source]#

Reduce image to 1D at specified point.

Parameters:
  • img – Input image array.

  • point – Point coordinates to extract.

  • keep_dim – Dimension to keep (others will be sliced at the point).

Returns:

1D array extracted from the image at the specified point.

Return type:

ndarray

ultrasound_metrics.metrics.fwhm.reduce_image_to_only_measurement_dimensions(
img: numpy.typing.NDArray[numpy.floating],
measurement_dimensions: numpy.typing.NDArray[numpy.integer],
) numpy.typing.NDArray[numpy.floating][source]#

Reduce image to only specified measurement dimensions.

Parameters:
  • img – Input image array.

  • measurement_dimensions – Dimensions to keep in the output.

Returns:

Image reduced to measurement dimensions only.

Return type:

ndarray

ultrasound_metrics.metrics.fwhm.reorder_measured_dims_into_original_shape(
fwhm_of_measured_dims: numpy.typing.NDArray[numpy.floating],
n_dim_of_input_image: int,
measurement_dimensions: numpy.typing.NDArray[numpy.integer],
) numpy.typing.NDArray[numpy.floating][source]#

Reorder the measured FWHM values into the original shape.

Parameters:
  • fwhm_of_measured_dims – FWHM values for measured dimensions.

  • n_dim_of_input_image – Number of dimensions in the original image.

  • measurement_dimensions – Dimensions that were measured.

Returns:

FWHM values reordered to match original image dimensions.

Return type:

ndarray

ultrasound_metrics.metrics.fwhm.set_default_measurement_dims(
img_shape: tuple[int, Ellipsis],
) numpy.typing.NDArray[numpy.integer][source]#

Set default measurement dimensions based on image shape.

Parameters:

img_shape – Shape of the input image.

Returns:

Array of valid measurement dimensions.

Return type:

ndarray

ultrasound_metrics.metrics.fwhm.IMG_DIM = 4[source]#