Transformation
- ultrasound_processing.transform.transform_image(img: PIL.Image.Image, alpha_deg: float, res: float)[source]
Transforms an ultrasound image into a rectified coordinate system.
- Parameters:
img (PIL.Image.Image) – Input image to process.
alpha_deg (float) – Half angle of the ultrasound beam in degrees.
res (float) – Image resolution scaling factor.
- Returns:
Transformed image as a 2D array.
Depth of the ultrasound window in pixels.
Offset from the top in centimeters.
- Return type:
Tuple[np.ndarray, float, float]
- ultrasound_processing.transform.convert_to_grayscale(image)[source]
Converts a PIL image to a grayscale NumPy array.
- Parameters:
image (PIL.Image.Image) – Input image in PIL.Image format.
- Returns:
Grayscale image as a 2D NumPy array.
- Return type:
np.ndarray
- ultrasound_processing.transform.detect_cm_marks(gray_array)[source]
Detects centimeter marks in the grayscale image along rows and columns.
- Parameters:
gray_array (np.ndarray) – Grayscale image array.
- Returns:
Estimated distance in pixels between cm marks (float).
List of detected row indices (List[int]).
List of detected column indices (List[int]).
- Return type:
Tuple[float, List[int], List[int]]
- ultrasound_processing.transform.clean_image(gray_array)[source]
Cleans the grayscale image by cropping and filtering pixel values.
- Parameters:
gray_array (np.ndarray) – Grayscale image array.
- Returns:
Processed image as a float array with noise filtered.
Index of the first row retained after cropping.
- Return type:
Tuple[np.ndarray, int]
- ultrasound_processing.transform.calculate_geometry(temp, d, alpha)[source]
Calculates geometric parameters from the ultrasound image.
- Parameters:
temp (np.ndarray) – Cleaned image array.
d (float) – Pixel-to-centimeter ratio.
alpha (float) – Half angle of the ultrasound beam in radians.
- Returns:
Depth of the offset in pixels.
Height in pixels of the ultrasound window.
Offset in centimeters.
Height in centimeters of the ultrasound window.
First row index of the window.
- Return type:
Tuple[float, int, float, float, int]
- ultrasound_processing.transform.compute_coordinate_grid(offset_cm, r_cm, d, temp, offset_px, first, alpha_deg, res)[source]
Computes the coordinate grid for the ultrasound image transformation.
- Parameters:
offset_cm (float) – Offset in centimeters.
r_cm (float) – Range in centimeters.
d (float) – Pixel-to-centimeter ratio.
temp (np.ndarray) – Processed grayscale image.
offset_px (float) – Offset in pixels.
first (int) – Index of the first pixel row used.
alpha_deg (float) – Half angle of ultrasound beam in degrees.
res (float) – Image resolution scaling factor.
- Returns:
X coordinates in the transformed space.
Y coordinates in the transformed space.
- Return type:
Tuple[np.ndarray, np.ndarray]
- ultrasound_processing.transform.interpolate_image(X, Y, temp)[source]
Applies bilinear interpolation to map intensity values from input coordinates.
- Parameters:
X (np.ndarray) – X coordinate grid.
Y (np.ndarray) – Y coordinate grid.
temp (np.ndarray) – Processed grayscale image.
- Returns:
Interpolated intensity values.
- Return type:
np.ndarray