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_contourslist of np.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.

Returns:
subsegment_areasarray of floats

Array containing the area of each incremental subsegment.

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_rasnp.ndarray

Array of shape (2, N) containing contour points in RAS space.

Returns:
pt0np.ndarray

Starting point for eigenvector line.

pt1np.ndarray

End point for eigenvector line.

CorpusCallosum.shape.subsegment_contour.get_unique_contour_points(split_contours)[source]

Get unique contour points from the split contours.

Parameters:
split_contoursContourList

List of split contours (subsegmentations), each containing x and y coordinates, each of shape (2, N).

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:
contournp.ndarray

Array of shape (2, N) containing contour points.

num_raysint

Number of rays to use for subdivision.

plotbool, optional

Whether to plot the results, by default False.

axmatplotlib.axes.Axes, optional

Axes for plotting, by default None.

Returns:
areasnp.ndarray

Array of areas for each subsegment.

split_contourslist[np.ndarray]

List of contour arrays for each subsegment.

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:
pointsarray

An array of shape (N, 2) containing point coordinates.

Returns:
np.ndarray

Array 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:
contournp.ndarray

Array of shape (2, N) containing contour points.

area_weightslist[float]

List of weights for area-based subdivision.

plotbool, optional

Whether to plot the results, by default False.

axmatplotlib.axes.Axes, optional

Axes for plotting, by default None.

plot_transformcallable(), optional

Function to transform points before plotting, by default None.

orientedbool, optional

If True, use fixed horizontal reference line, by default False.

hline_anchornp.ndarray, optional

Point to anchor horizontal reference line, by default None.

Returns:
areasnp.ndarray

Array of areas for each subsegment.

split_contourslist[np.ndarray]

List of contour arrays for each subsegment.

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:
midlinearray of floats

Array of shape (N, 2) containing midline points.

area_weightsarray of floats

Array of weights for area-based subdivision.

contourarray of floats

Array of shape (2, M) containing contour points in as space.

plotbool, optional

Whether to plot the results, by default True.

axmatplotlib.axes.Axes, optional

Axes for plotting, by default None.

extremestuple, optional

Tuple of extreme points, by default None.

Returns:
subsegment_areasarray of floats

List of subsegment areas.

split_contourslist of np.ndarray

List of contour arrays for each subsegment.

split_pointsnp.ndarray

Array of shape (K, 2) containing points where the midline was split.

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:
  1. Translating AC point to origin.

  2. Rotating to align PC point with posterior direction.

  3. Scaling to maintain AC-PC distance.

Parameters:
contour_rasarray of floats

Array of shape (2, N) or (3, N) containing contour points in RAS space.

ac_pt_rasnp.ndarray

Anterior commissure point coordinates in AS space.

pc_pt_rasnp.ndarray

Posterior commissure point coordinates in AS space.

Returns:
contour_acpcnp.ndarray

Transformed contour points in AC-PC space.

ac_pt_acpcnp.ndarray

AC point in AC-PC space (origin).

pc_pt_acpcnp.ndarray

PC point in AC-PC space.

rotate_backcallable()

Function to transform points back to RAS space.