zea.tools.fit_scan_cone

Identifies the scan cone of an ultrasound image and crops it such that the apex of the cone is at the top center of the image. In this form, it can be scan converted to polar coordinates.

This module provides functionality to: 1. Detect the scan cone boundaries in ultrasound images 2. Fit lines to the cone edges 3. Calculate cone parameters (apex position, opening angle, etc.) 4. Crop and center the image around the cone 5. Visualize the detected cone and its parameters

Functions

crop_and_center_cone(image, cone_params)

Crop the image to the sector bounding box and pad as needed to center the apex.

detect_cone_parameters(image[, ...])

Detect the ultrasound cone parameters from a grayscale image.

filter_edge_points_by_boundary(edge_points)

Filter edge points to keep only those that form the actual boundary of the scan cone.

fit_and_crop_around_scan_cone(image_tensor)

Detect scan cone in ultrasound image and return cropped/padded image with centered apex.

get_args()

Parse command line arguments.

main(avi_path)

Demonstrate scan cone fitting on a sample AVI file.

visualize_scan_cone(image, cone_params[, ...])

Create visualization plots for the scan cone detection.

zea.tools.fit_scan_cone.crop_and_center_cone(image, cone_params)[source]

Crop the image to the sector bounding box and pad as needed to center the apex.

This function: 1. Crops the image to the detected cone boundaries 2. Adds padding if the apex is above the image 3. Centers the apex horizontally in the final image

Parameters:
  • image – 2D Keras tensor (grayscale image)

  • cone_params – Dictionary of cone parameters from detect_cone_parameters()

Returns:

Keras tensor of the cropped and centered image with the cone apex at the top center

zea.tools.fit_scan_cone.detect_cone_parameters(image, min_cone_half_angle_deg=20, threshold=15)[source]

Detect the ultrasound cone parameters from a grayscale image.

This function performs the following steps: 1. Thresholds the image to create a binary mask 2. Detects left and right edge points of the cone 3. Filters edge points to ensure physical constraints 4. Fits lines to the cone boundaries 5. Calculates cone parameters including apex position, opening angle, and crop boundaries

Parameters:
  • image – 2D Keras tensor (grayscale image)

  • min_cone_half_angle_deg – Minimum expected half-angle of the cone in degrees

  • threshold – Threshold for binary image (pixels above this are considered data)

Returns:

  • apex_x, apex_y: Coordinates of the cone apex

  • crop_left, crop_right, crop_top, crop_bottom: Crop boundaries

  • cone_height: Height of the cone

  • opening_angle: Opening angle of the cone

  • symmetry_ratio: Measure of cone symmetry

  • data_coverage: Fraction of crop region containing data

  • And other geometric parameters

Return type:

Dictionary containing cone parameters including

Raises:

ValueError – If input image is not 2D or cone detection fails

zea.tools.fit_scan_cone.filter_edge_points_by_boundary(edge_points, is_left=True, min_cone_half_angle_deg=20)[source]

Filter edge points to keep only those that form the actual boundary of the scan cone. Enforces minimum cone angle constraint to ensure valid cone shapes.

Parameters:
  • edge_points – Tensor of shape (N, 2) containing (x, y) coordinates of edge points

  • is_left – Boolean indicating whether these are left (True) or right (False) edge points

  • min_cone_half_angle_deg – Minimum expected half-angle of the cone in degrees

Returns:

Tensor of shape (M, 2) containing filtered edge points that satisfy the boundary constraints

zea.tools.fit_scan_cone.fit_and_crop_around_scan_cone(image_tensor, min_cone_half_angle_deg=20, threshold=15, return_params=False)[source]

Detect scan cone in ultrasound image and return cropped/padded image with centered apex.

Parameters:
  • image_tensor – Keras tensor (2D grayscale image)

  • min_cone_half_angle_deg – Minimum expected half-angle of the cone in degrees (default: 20)

  • threshold – Threshold for binary image - pixels above this are considered data (default: 15)

  • return_params – If True, also return cone parameters (default: False)

Returns:

Keras tensor (cropped and padded image with apex at center) - If return_params is True: Tuple of (cropped_tensor, cone_parameters_dict)

Return type:

  • If return_params is False

Raises:

ValueError – If cone detection fails or image is not 2D

zea.tools.fit_scan_cone.get_args()[source]

Parse command line arguments.

zea.tools.fit_scan_cone.main(avi_path)[source]

Demonstrate scan cone fitting on a sample AVI file.

zea.tools.fit_scan_cone.visualize_scan_cone(image, cone_params, output_dir='output')[source]

Create visualization plots for the scan cone detection.

Parameters:
  • image – Original grayscale image

  • cone_params – Dictionary of cone parameters from detect_cone_parameters()

  • output_dir – Directory to save output plots (default: “output”)

The visualization is saved as ‘scan_cone_visualization.png’ in the output directory.