xcal.phantom

Functions:

generate_circle_masks(side_length, ...)

Generate a set of small, non-overlapping circular masks with their centers evenly distributed along the circumference of a larger circle, all contained within a square canvas.

xcal.phantom.generate_circle_masks(side_length, pixel_size, num_circles, outer_cir_radius, inner_cir_radius)[source]

Generate a set of small, non-overlapping circular masks with their centers evenly distributed along the circumference of a larger circle, all contained within a square canvas.

Parameters:
  • side_length (float) – The side length of the square canvas that the circles will be placed on, measured in millimeters (mm). This defines the workspace for the circle generation.

  • pixel_size (float) – The size of each pixel in the canvas, given in millimeters (mm), which determines the resolution of the created masks.

  • num_circles (int) – The number of non-overlapping small circles to generate.

  • outer_cir_radius (float) – The radius of the larger circle on whose circumference the centers of the small circles will be placed, measured in millimeters (mm).

  • inner_cir_radius (float) – The radius of each small inner circle mask, measured in millimeters (mm). The small circles will have their centers on the larger circle’s circumference and should not overlap with each other.

Returns:

A list containing the circle masks, where each mask is represented by a boolean NumPy array with True values indicating the presence of the circle mask and False values indicating absence.

xcal.phantom.detect_hough_circles(phantom, radius_range=None, vmin=0, vmax=None, min_dist=100, HoughCircles_params1=300, HoughCircles_params2=1)[source]

Detects circles in an image using the Hough Circle Transform.

Parameters:
  • phantom (numpy.ndarray) – The 2D image to detect circles in.

  • radius_range (list of int, optional) – The minimum and maximum radius of circles to detect. Defaults to a range based on the image size.

  • vmin (int, optional) – Minimum value for clipping the image before detection. Defaults to 0.

  • vmax (int, optional) – Maximum value for clipping the image before detection. If None, the 90th percentile of the image is used. Defaults to None.

  • min_dist (int, optional) – Minimum distance between the centers of the detected circles. If too small, multiple neighbor circles may be falsely detected in addition to a true one. If too large, some circles may be missed. Defaults to 100.

  • HoughCircles_params1 (float, optional) – Upper threshold for the internal edge detection.

  • HoughCircles_params2 (float, optional) – Threshold for center detection, which influences the detection sensitivity. Large param2 leads to fewer detected circles.

Returns:

An array of detected circles, each represented by the

center coordinates (x, y) and radius. Returns an empty array if no circles are detected.

Return type:

numpy.ndarray

xcal.phantom.segment_object(phantom, vmin, vmax, canny_sigma, roi_radius=None, bbox=None)[source]

Segments an object within a given region of interest (ROI) or bounding box in an image.

This function creates a segmentation mask for an object in an image. The image values are clipped and normalized based on provided minimum and maximum values. Canny edge detection is then applied to the normalized image. The edges are filled to create a binary mask that segments the object.

Parameters:
  • phantom (np.array) – The input image to segment.

  • vmin (float) – The minimum value for clipping the image.

  • vmax (float) – The maximum value for clipping the image.

  • canny_sigma (float) – The standard deviation for the Gaussian filter used in Canny edge detection.

  • roi_radius (int, optional) – The radius of the circular region of interest. If not provided, it defaults to half the image size.

  • bbox (tuple of int, optional) – The bounding box within which to perform segmentation, specified as (r_min, c_min, r_max, c_max). If not provided, the entire image is used.

Returns:

A binary segmentation mask of the object.

Return type:

np.array