CorpusCallosum.segmentation.segmentation_postprocessing¶
- CorpusCallosum.segmentation.segmentation_postprocessing.clean_cc_segmentation(seg_arr, max_connection_distance=3.0)[source]¶
Clean corpus callosum segmentation by removing non-connected components.
- Parameters:
- Returns:
- CorpusCallosum.segmentation.segmentation_postprocessing.connect_nearby_components(seg_arr, max_connection_distance=3.0, plot=False)[source]¶
Connect nearby disconnected components that should be connected.
This function identifies disconnected components in the segmentation and creates minimal connections between components that are close to each other.
- Parameters:
- seg_arr
np.ndarray Input binary segmentation array.
- max_connection_distance
float, default=3.0 Maximum distance to connect components.
- plot
bool, default=False Whether to plot the segmentation with connected components.
- seg_arr
- Returns:
np.ndarraySegmentation array with minimal connections added between nearby components.
Notes
The function: 1. Identifies connected components in the input segmentation 2. Finds boundaries between components 3. Creates minimal connections between nearby components 4. Returns the modified segmentation with added connections
- CorpusCallosum.segmentation.segmentation_postprocessing.create_connection_line(point1, point2)[source]¶
Create a line of voxels connecting two points.
Uses a simplified 3D line algorithm to create a sequence of voxels that form a continuous path between the two points.
- Parameters:
- point1
np.ndarray Starting point coordinates, shape (3,).
- point2
np.ndarray Ending point coordinates, shape (3,).
- point1
- Returns:
Notes
The line is created by interpolating between the points using the maximum distance in any dimension as the number of steps.
- CorpusCallosum.segmentation.segmentation_postprocessing.extract_largest_connected_component(seg_arr, max_connection_distance=3.0)[source]¶
Get the largest connected component from a binary segmentation array.
- Parameters:
- seg_arr
np.ndarray Input binary segmentation array.
- max_connection_distance
float,optional Maximum distance to connect components, by default 3.0.
- seg_arr
- Returns:
np.ndarrayBinary mask of the largest connected component.
Notes
The function first attempts to connect nearby disconnected components that should be connected, then finds the largest connected component. It uses minimal connections between close components before falling back to dilation if no connections are made.
- CorpusCallosum.segmentation.segmentation_postprocessing.find_component_boundaries(labels_arr, component_id)[source]¶
Find boundary voxels of a connected component.
- Parameters:
- labels_arr
np.ndarray Labeled array from connected components analysis.
- component_id
int ID of the component to find boundaries for.
- labels_arr
- Returns:
np.ndarrayArray of shape (N, 3) containing boundary coordinates.
Notes
Uses 6-connectivity (face neighbors only) to determine boundaries. Boundary voxels are those that are part of the component but have at least one non-component neighbor.
- CorpusCallosum.segmentation.segmentation_postprocessing.find_minimal_connection_path(boundary_coords1, boundary_coords2, max_distance=3.0)[source]¶
Find the minimal connection path between two component boundaries.
- Parameters:
- boundary_coords1
np.ndarray Boundary coordinates of first component, shape (N1, 3).
- boundary_coords2
np.ndarray Boundary coordinates of second component, shape (N2, 3).
- max_distance
float, default=3.0 Maximum distance to consider for connection, by default 3.0.
- boundary_coords1
- Returns:
tuple[np.ndarray,np.ndarray]orNoneIf a valid connection is found:
point1 : Coordinates on first boundary
point2 : Coordinates on second boundary
None if no connection within max_distance is found.
Notes
Uses Euclidean distance to find the closest pair of points between the two boundaries.
- CorpusCallosum.segmentation.segmentation_postprocessing.get_cc_volume_voxel(desired_width_mm, cc_mask, voxel_size)[source]¶
Calculate the volume of the corpus callosum in cubic millimeters.
This function calculates the volume of the corpus callosum (CC) in cubic millimeters. If the CC width is larger than desired_width_mm, the voxels on the edges are calculated as partial volumes to achieve the desired width.
- Parameters:
- desired_width_mm
int Desired width of the CC in millimeters.
- cc_mask
np.ndarray Binary mask of the corpus callosum in LIA orientation.
- voxel_size
tripletoffloats LIA-oriented Voxel size in millimeters (x, y, z).
- desired_width_mm
- Returns:
floatVolume of the CC in cubic millimeters.
- Raises:
ValueErrorIf CC width is smaller than desired width
AssertionErrorIf CC mask doesn’t have odd number of voxels in x dimension
Notes
The function assumes LIA orientation