ultrasound_metrics.metrics.fwhm
===============================

.. py:module:: ultrasound_metrics.metrics.fwhm

.. autoapi-nested-parse::

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



Attributes
----------

.. autoapisummary::

   ultrasound_metrics.metrics.fwhm.IMG_DIM


Functions
---------

.. autoapisummary::

   ultrasound_metrics.metrics.fwhm.calculate_fwhm_from_2D_gaussian_fit
   ultrasound_metrics.metrics.fwhm.calculate_fwhm_from_var
   ultrasound_metrics.metrics.fwhm.calculate_linear_interpolation
   ultrasound_metrics.metrics.fwhm.calculate_var_from_fwhm
   ultrasound_metrics.metrics.fwhm.compute_fwhm
   ultrasound_metrics.metrics.fwhm.convert_fwhm_to_input_units
   ultrasound_metrics.metrics.fwhm.crop_image_around_max
   ultrasound_metrics.metrics.fwhm.find_max_idx_within_expected_target_radius
   ultrasound_metrics.metrics.fwhm.fit_2d_gaussian
   ultrasound_metrics.metrics.fwhm.gaussian_2d
   ultrasound_metrics.metrics.fwhm.get_subscript_idx_of_target_max_within_roi
   ultrasound_metrics.metrics.fwhm.measure_fwhm_of_target
   ultrasound_metrics.metrics.fwhm.measure_half_width_half_max
   ultrasound_metrics.metrics.fwhm.measure_sub_pixel_fwhm
   ultrasound_metrics.metrics.fwhm.reduce_image_to_1D_at_point
   ultrasound_metrics.metrics.fwhm.reduce_image_to_only_measurement_dimensions
   ultrasound_metrics.metrics.fwhm.reorder_measured_dims_into_original_shape
   ultrasound_metrics.metrics.fwhm.set_default_measurement_dims


Module Contents
---------------

.. py:function:: 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]

   Calculate FWHM from 2D Gaussian fit.

   :param img: Input 2D image array.
   :param img_max_idx: Index of maximum value in the image.
   :param fwhm: Initial FWHM estimate.

   :returns: FWHM values from the Gaussian fit.
   :rtype: ndarray


.. py:function:: calculate_fwhm_from_var(var: numpy.typing.NDArray[numpy.floating]) -> numpy.typing.NDArray[numpy.floating]

   Calculate FWHM from variance.

   :param var: Variance values.

   :returns: FWHM values.
   :rtype: ndarray


.. py:function:: calculate_linear_interpolation(a: float, b: float, a_idx: int, b_idx: int, interp_val: float) -> float

   Calculate linear interpolation between two points.

   :param a: Value at first point.
   :param b: Value at second point.
   :param a_idx: Index of first point.
   :param b_idx: Index of second point.
   :param interp_val: Value to interpolate to.

   :returns: Interpolated index value.
   :rtype: float


.. py:function:: calculate_var_from_fwhm(fwhm: numpy.typing.NDArray[numpy.floating]) -> numpy.typing.NDArray[numpy.floating]

   Calculate variance from FWHM.

   :param fwhm: Full-width at half-maximum values.

   :returns: Variance values.
   :rtype: ndarray


.. py:function:: compute_fwhm(img: numpy.typing.NDArray[numpy.floating], roi_indices: Optional[numpy.typing.NDArray[numpy.integer]] = None, dims_to_measure: Optional[numpy.typing.NDArray[numpy.integer]] = None, target_radius: Optional[int] = None, bf_grid_spacing: Optional[numpy.typing.NDArray[numpy.floating]] = None, img_save_filename: Optional[str] = None) -> tuple[Optional[float], Ellipsis]

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

   :param img: The input image.
   :param roi_indices: Region of interest in the form of array indices.
   :param 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.
   :param 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.
   :param 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.
   :param 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.
   :rtype: tuple


.. py:function:: convert_fwhm_to_input_units(fwhm: numpy.typing.NDArray[numpy.floating], bf_grid_spacing: numpy.typing.NDArray[numpy.floating]) -> numpy.typing.NDArray[numpy.floating]

   Convert FWHM from pixels to physical units.

   :param fwhm: FWHM values in pixels.
   :param bf_grid_spacing: Grid spacing for unit conversion.

   :returns: FWHM values in physical units.
   :rtype: ndarray


.. py:function:: 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]]

   Crop image around maximum value.

   :param img: Input image array.
   :param img_max_idx: Index of maximum value in the image.
   :param fwhm: FWHM values for determining crop size.

   :returns: Cropped image and new maximum index within the cropped image.
   :rtype: tuple


.. py:function:: find_max_idx_within_expected_target_radius(img: numpy.typing.NDArray[numpy.floating], img_max_idx: tuple[int, Ellipsis], radius: int) -> tuple[int, Ellipsis]

   Find maximum index within expected target radius.

   :param img: Input image array.
   :param img_max_idx: Initial maximum index.
   :param radius: Search radius around the initial maximum.

   :returns: Index of maximum value within the specified radius.
   :rtype: tuple


.. py:function:: fit_2d_gaussian(img: numpy.typing.NDArray[numpy.floating], initial_guess: tuple[float, Ellipsis]) -> numpy.typing.NDArray[numpy.floating]

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

   :param img: Input 2D image array.
   :param initial_guess: Initial parameter guess for the Gaussian fit.

   :returns: Fitted Gaussian parameters.
   :rtype: ndarray


.. py:function:: 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]

   2D Gaussian function.

   :param xy: Tuple of (x, y) coordinate arrays.
   :param amplitude: Amplitude of the Gaussian.
   :param xo: X-coordinate of the center.
   :param yo: Y-coordinate of the center.
   :param sigma_x: Standard deviation in x-direction.
   :param sigma_y: Standard deviation in y-direction.
   :param theta: Rotation angle.
   :param offset: Vertical offset.

   :returns: Flattened Gaussian values.
   :rtype: ndarray


.. py:function:: get_subscript_idx_of_target_max_within_roi(img: numpy.typing.NDArray[numpy.floating], roi_indices: numpy.typing.NDArray[numpy.integer]) -> tuple[int, Ellipsis]

   Get subscript index of maximum value within ROI.

   :param img: Input image array.
   :param roi_indices: Indices defining the region of interest.

   :returns: Subscript index of the maximum value within the ROI.
   :rtype: tuple


.. py:function:: measure_fwhm_of_target(img: numpy.typing.NDArray[numpy.floating], img_max_idx: tuple[int, Ellipsis]) -> numpy.typing.NDArray[numpy.floating]

   Measure FWHM across all dimensions of the target.

   :param img: Input image array.
   :param img_max_idx: Index of the maximum value in the image.

   :returns: FWHM for each dimension.
   :rtype: ndarray


.. py:function:: measure_half_width_half_max(pixel_array: numpy.typing.NDArray[numpy.floating], max_val: float, use_interp: bool) -> float

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

   :param pixel_array: 1D pixel array.
   :param max_val: Maximum value in the array.
   :param use_interp: Whether to use linear interpolation for sub-pixel precision.

   :returns: Half-width at half-maximum.
   :rtype: float


.. py:function:: measure_sub_pixel_fwhm(im_line: numpy.typing.NDArray[numpy.floating], max_idx: int, max_val: float, use_interp: bool = True) -> float

   Measure the sub-pixel FWHM using linear interpolation.

   :param im_line: The 1-D orthogonal line across the target.
   :param max_idx: The index of the maximum position in the ROI.
   :param max_val: The value of the maximum position in the ROI.
   :param use_interp: Whether to use linear interpolation to obtain sub-pixel
                      precision.

   :returns: The sub-pixel FWHM.
   :rtype: float


.. py:function:: reduce_image_to_1D_at_point(img: numpy.typing.NDArray[numpy.floating], point: tuple[int, Ellipsis], keep_dim: int) -> numpy.typing.NDArray[numpy.floating]

   Reduce image to 1D at specified point.

   :param img: Input image array.
   :param point: Point coordinates to extract.
   :param keep_dim: Dimension to keep (others will be sliced at the point).

   :returns: 1D array extracted from the image at the specified point.
   :rtype: ndarray


.. py:function:: reduce_image_to_only_measurement_dimensions(img: numpy.typing.NDArray[numpy.floating], measurement_dimensions: numpy.typing.NDArray[numpy.integer]) -> numpy.typing.NDArray[numpy.floating]

   Reduce image to only specified measurement dimensions.

   :param img: Input image array.
   :param measurement_dimensions: Dimensions to keep in the output.

   :returns: Image reduced to measurement dimensions only.
   :rtype: ndarray


.. py:function:: 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]

   Reorder the measured FWHM values into the original shape.

   :param fwhm_of_measured_dims: FWHM values for measured dimensions.
   :param n_dim_of_input_image: Number of dimensions in the original image.
   :param measurement_dimensions: Dimensions that were measured.

   :returns: FWHM values reordered to match original image dimensions.
   :rtype: ndarray


.. py:function:: set_default_measurement_dims(img_shape: tuple[int, Ellipsis]) -> numpy.typing.NDArray[numpy.integer]

   Set default measurement dimensions based on image shape.

   :param img_shape: Shape of the input image.

   :returns: Array of valid measurement dimensions.
   :rtype: ndarray


.. py:data:: IMG_DIM
   :value: 4


