CorpusCallosum.shape.subsegment_contour¶
- CorpusCallosum.shape.subsegment_contour.calc_subsegment_areas(split_contours)[source]¶
Calculate area of each subsegment using the shoelace formula.
- Parameters:
- split_contours
listofnp.ndarray List of contour arrays, each of shape (2, N). The list should contain a set of nested contours (cumulative subsegments) and the full contour.
- split_contours
- Returns:
- subsegment_areas
arrayoffloats Array containing the area of each incremental subsegment.
- subsegment_areas
- CorpusCallosum.shape.subsegment_contour.get_primary_eigenvector(contour_ras)[source]¶
Calculate primary eigenvector of contour points using PCA.
Computes the principal direction of the contour by: 1. Centering the points 2. Computing covariance matrix 3. Finding eigenvectors 4. Selecting primary direction
- Parameters:
- contour_ras
np.ndarray Array of shape (2, N) containing contour points in RAS space.
- contour_ras
- Returns:
- pt0
np.ndarray Starting point for eigenvector line.
- pt1
np.ndarray End point for eigenvector line.
- pt0
- CorpusCallosum.shape.subsegment_contour.get_unique_contour_points(split_contours)[source]¶
Get unique contour points from the split contours.
- Parameters:
- split_contours
ContourList List of split contours (subsegmentations), each containing x and y coordinates, each of shape (2, N).
- split_contours
- Returns:
list[np.ndarray]List of unique contour points for each subsegment, each of shape (N, 2).
Notes
This is a workaround to retrospectively add voxel-based subdivision. In the future, we could keep track of the subdivision lines for every subdivision scheme.
The function: 1. Processes each contour point. 2. Checks if it appears in other contours (with small tolerance). 3. Collects points unique to each subsegment.
- CorpusCallosum.shape.subsegment_contour.hampel_subdivide_contour(contour, num_rays, plot=False, ax=None)[source]¶
Subdivide contour based on area weights using equally spaced rays.
- Parameters:
- contour
np.ndarray Array of shape (2, N) containing contour points.
- num_rays
int Number of rays to use for subdivision.
- plot
bool,optional Whether to plot the results, by default False.
- ax
matplotlib.axes.Axes,optional Axes for plotting, by default None.
- contour
- Returns:
- areas
np.ndarray Array of areas for each subsegment.
- split_contours
list[np.ndarray] List of contour arrays for each subsegment.
- areas
Notes
The subdivision process: 1. Finds extreme points in x-direction. 2. Creates minimal bounding rectangle around contour. 3. Creates equally spaced rays from lower edge of rectangle. 4. Finds intersections of rays with contour. 5. Creates new contours by splitting at intersections. 6. Returns areas and split contours.
- CorpusCallosum.shape.subsegment_contour.minimum_bounding_rectangle(points)[source]¶
Find the smallest bounding rectangle for a set of points.
- Parameters:
- points
array An array of shape (N, 2) containing point coordinates.
- points
- Returns:
np.ndarrayArray of shape (4, 2) containing coordinates of the bounding box corners.
- CorpusCallosum.shape.subsegment_contour.subdivide_contour(contour, area_weights, plot=False, ax=None, plot_transform=None, oriented=False, hline_anchor=None)[source]¶
Subdivide contour based on area weights using vertical lines.
Divides the contour into segments by drawing vertical lines at positions determined by the area weights. The lines are drawn perpendicular to a reference line connecting the extreme points of the contour.
- Parameters:
- contour
np.ndarray Array of shape (2, N) containing contour points.
- area_weights
list[float] List of weights for area-based subdivision.
- plot
bool,optional Whether to plot the results, by default False.
- ax
matplotlib.axes.Axes,optional Axes for plotting, by default None.
- plot_transform
callable(),optional Function to transform points before plotting, by default None.
- oriented
bool,optional If True, use fixed horizontal reference line, by default False.
- hline_anchor
np.ndarray,optional Point to anchor horizontal reference line, by default None.
- contour
- Returns:
- areas
np.ndarray Array of areas for each subsegment.
- split_contours
list[np.ndarray] List of contour arrays for each subsegment.
- areas
Notes
The subdivision process: 1. Finds extreme points in x-direction. 2. Creates reference line between extremes. 3. Calculates split points based on area weights. 4. Divides contour using perpendicular lines at split points.
- CorpusCallosum.shape.subsegment_contour.subsegment_midline_orthogonal(midline, area_weights, contour, plot=True, ax=None, extremes=None)[source]¶
Subsegment contour orthogonally to the midline based on area weights.
- Parameters:
- midline
arrayoffloats Array of shape (N, 2) containing midline points.
- area_weights
arrayoffloats Array of weights for area-based subdivision.
- contour
arrayoffloats Array of shape (2, M) containing contour points in as space.
- plot
bool,optional Whether to plot the results, by default True.
- ax
matplotlib.axes.Axes,optional Axes for plotting, by default None.
- extremes
tuple,optional Tuple of extreme points, by default None.
- midline
- Returns:
- subsegment_areas
arrayoffloats List of subsegment areas.
- split_contours
listofnp.ndarray List of contour arrays for each subsegment.
- split_points
np.ndarray Array of shape (K, 2) containing points where the midline was split.
- subsegment_areas
Notes
Subsegments include all previous segments. This means subsegment contour two is the outline of the union of subsegment one and subsegment two.
- CorpusCallosum.shape.subsegment_contour.transform_to_acpc_standard(contour_ras, ac_pt_ras, pc_pt_ras)[source]¶
Transform contour coordinates to AC-PC standard space.
- Transforms the contour coordinates by:
Translating AC point to origin.
Rotating to align PC point with posterior direction.
Scaling to maintain AC-PC distance.
- Parameters:
- contour_ras
arrayoffloats Array of shape (2, N) or (3, N) containing contour points in RAS space.
- ac_pt_ras
np.ndarray Anterior commissure point coordinates in AS space.
- pc_pt_ras
np.ndarray Posterior commissure point coordinates in AS space.
- contour_ras
- Returns:
- contour_acpc
np.ndarray Transformed contour points in AC-PC space.
- ac_pt_acpc
np.ndarray AC point in AC-PC space (origin).
- pc_pt_acpc
np.ndarray PC point in AC-PC space.
- rotate_back
callable() Function to transform points back to RAS space.
- contour_acpc