CorpusCallosum.shape.endpoint_heuristic

CorpusCallosum.shape.endpoint_heuristic.connect_diagonally_connected_components(cc_mask)[source]

Connect diagonally connected components in the CC mask.

Parameters:
cc_masknp.ndarray

Binary mask of the corpus callosum.

Notes

Modifies the input mask in-place to connect diagonally connected components.

CorpusCallosum.shape.endpoint_heuristic.extract_cc_contour(cc_mask, contour_smoothing=5)[source]

Extract the contour of the CC from the mask using a marching squares approach.

Parameters:
cc_masknp.ndarray

Binary mask of the corpus callosum.

contour_smoothingint, default=5

Window size for contour smoothing.

Returns:
lapy.Polygon

A lapy Polygon object with a closed polygon contour.

CorpusCallosum.shape.endpoint_heuristic.find_cc_endpoints(contour, ac_2d, pc_2d, plot=False)[source]

Extracts the contour of the CC, rotates to AC-PC alignment, and determines closest points of CC to AC and PC.

Parameters:
contournp.ndarray of shape (2, N)

Points of the CC contour in AS (millimeter).

ac_2dnp.ndarray of shape (2,) and type float

2D AS coordinates of the anterior commissure in millimeter.

pc_2dnp.ndarray of shape (2,) and type float

2D AS coordinates of the posterior commissure in millimeter.

Returns:
anterior_posterior_point_indicespair of ints

Indices of anterior and posterior points in the contour.

Notes

Expects AS orientation of contour, ac_2d, and pc_2d.

CorpusCallosum.shape.endpoint_heuristic.smooth_contour(x, y, window_size)[source]

Smooth a contour using a moving average filter.

Parameters:
xnp.ndarray

X-coordinates of the contour points.

ynp.ndarray

Y-coordinates of the contour points.

window_sizeint

Size of the smoothing window. Must be odd and > 2.

Returns:
tuple[np.ndarray, np.ndarray]

Smoothed x and y coordinates of the contour.