Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions CorpusCallosum/fastsurfer_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ def _orig2midslab_vox2vox(additional_context: int = 0) -> AffineMatrix4x4:
# Process slices based on selection mode

logger.info(f"Processing slices with selection mode: {slice_selection}")
slice_results, slice_io_futures, cc_contours, cc_mesh = recon_cc_surf_measures_multi(
slice_results, slice_io_futures, cc_contours = recon_cc_surf_measures_multi(
segmentation=cc_fn_seg_labels,
slice_selection=slice_selection,
upright_header=fsavg_header,
Expand Down Expand Up @@ -883,8 +883,8 @@ def _orig2midslab_vox2vox(additional_context: int = 0) -> AffineMatrix4x4:
if len(middle_slice_result["split_contours"]) <= 5:
cc_subseg_midslice = make_subdivision_mask(
(cc_fn_seg_labels.shape[1], cc_fn_seg_labels.shape[2]),
middle_slice_result["split_contours"],
vox2ras=fsavg_vox2ras @ np.linalg.inv(fsavg2midslice_vox2vox),
middle_slice_result["subdivision_lines"],
vox2ras=fsavg_vox2ras @ np.linalg.inv(fsavg2midslice_vox2vox)
)
else:
logger.warning("Too many subsegments for lookup table, skipping sub-division of output segmentation.")
Expand Down Expand Up @@ -914,22 +914,24 @@ def _orig2midslab_vox2vox(additional_context: int = 0) -> AffineMatrix4x4:

########## Save outputs ##########
additional_metrics = {}
if len(outer_contours) > 1:
cc_volume_voxel = segmentation_postprocessing.get_cc_volume_voxel(

cc_volume_voxel = segmentation_postprocessing.get_cc_volume_voxel(
desired_width_mm=5,
cc_mask=np.equal(cc_fn_seg_labels, CC_LABEL),
voxel_size=vox_size, # in LIA order
)
additional_metrics["cc_5mm_volume"] = cc_volume_voxel


if len(outer_contours) > 1:
logger.info(f"CC volume voxel: {cc_volume_voxel}")
cc_volume_contour = calculate_cc_volume_contour(cc_contours, width=5.0)
logger.info(f"CC volume contour: {cc_volume_contour}")

additional_metrics["cc_5mm_volume"] = cc_volume_voxel
additional_metrics["cc_5mm_volume_pv_corrected"] = cc_volume_contour

# get ac and pc in all spaces
ac_coords_3d = np.hstack((FSAVERAGE_MIDDLE, ac_coords_vox))
pc_coords_3d = np.hstack((FSAVERAGE_MIDDLE, pc_coords_vox))
ac_coords_3d = np.hstack((FSAVERAGE_MIDDLE / vox_size[0], ac_coords_vox))
pc_coords_3d = np.hstack((FSAVERAGE_MIDDLE / vox_size[0], pc_coords_vox))
standardized2orig_vox2vox, ac_coords_standardized, pc_coords_standardized, ac_coords_orig, pc_coords_orig = (
calc_mapping_to_standard_space(orig, ac_coords_3d, pc_coords_3d, orig2fsavg_vox2vox)
)
Comment thread
dkuegler marked this conversation as resolved.
Expand Down
2 changes: 1 addition & 1 deletion CorpusCallosum/localization/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def predict(

crop_left, crop_top = cast(tuple[int, int], t_dict["crop_left"]), cast(tuple[int, int], t_dict["crop_top"])
t_crops = [(crop_left + crop_top) * 2]
outs: np.ndarray[tuple[int, Literal[4]], np.dtype[np.float_]]
outs: np.ndarray[tuple[int, Literal[4]], np.dtype[np.float64]]
outs = outputs.cpu().numpy() + np.asarray(t_crops, dtype=float)
crop_offsets: tuple[int, int] = (crop_left[0], crop_top[0])
return outs[:, :2], outs[:, 2:], crop_offsets
Expand Down
4 changes: 2 additions & 2 deletions CorpusCallosum/shape/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class CCContour:
def __init__(
self,
points: Points2dType,
thickness_values: np.ndarray[tuple[int], np.dtype[np.float_]] | None,
thickness_values: np.ndarray[tuple[int], np.dtype[np.float64]] | None,
endpoint_idxs: tuple[int, int] | None = None,
z_position: float = 0.0
):
Expand Down Expand Up @@ -740,7 +740,7 @@ def _load_thickness_values(
contour: Points2dType,
original_thickness_vertices: np.ndarray[tuple[int], np.dtype[np.signedinteger]] | None,
input_path: str | Path,
) -> np.ndarray[tuple[int], np.dtype[np.float_]]:
) -> np.ndarray[tuple[int], np.dtype[np.float64]]:
"""See load_thickness_values.

Ignore shape of thickness values if original_thickness_vertices is None.
Expand Down
28 changes: 7 additions & 21 deletions CorpusCallosum/shape/curvature.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

import numpy as np

from CorpusCallosum.utils.types import ContourList, Points2dType
from CorpusCallosum.utils.types import Points2dType


def compute_curvature(path: Points2dType) -> np.ndarray[tuple[int], np.dtype[np.float_]]:
def compute_curvature(path: Points2dType) -> np.ndarray[tuple[int], np.dtype[np.float64]]:
"""Compute curvature by computing edge angles.

Parameters
Expand Down Expand Up @@ -61,8 +61,7 @@ def compute_mean_curvature(path: Points2dType) -> float:

def calculate_curvature_metrics(
midline: Points2dType,
split_points: np.ndarray | None = None,
split_contours: ContourList | None = None,
split_points: np.ndarray,
) -> tuple[float, float, np.ndarray]:
Comment thread
m-reuter marked this conversation as resolved.
"""
Calculate curvature metrics for the CC midline, including overall mean,
Expand All @@ -72,10 +71,8 @@ def calculate_curvature_metrics(
----------
midline : Points2dType
Equidistant points along the midline.
split_points : np.ndarray, optional
split_points : np.ndarray
Points on the midline where it was split (for orthogonal subdivision).
split_contours : ContourList, optional
List of split contours (for other subdivision methods).

Returns
-------
Expand All @@ -96,20 +93,9 @@ def calculate_curvature_metrics(

# Find split indices on the midline for subsegment curvature
split_indices_midline = [0]
if split_points is not None:
for sp in split_points:
idx = np.argmin(np.linalg.norm(midline - sp, axis=1))
split_indices_midline.append(idx)
elif split_contours is not None:
from CorpusCallosum.shape.subsegment_contour import get_unique_contour_points
unique_points = get_unique_contour_points(split_contours)
for line_pts in unique_points[1:]:
if len(line_pts) == 2:
# find where this line crosses the midline
# use the average of the two points and find closest point on midline
mid_pt = np.mean(line_pts, axis=0)
idx = np.argmin(np.linalg.norm(midline - mid_pt, axis=1))
split_indices_midline.append(idx)
for sp in split_points:
idx = np.argmin(np.linalg.norm(midline - sp, axis=1))
split_indices_midline.append(idx)

split_indices_midline.append(len(midline) - 1)
split_indices_midline.sort()
Expand Down
Loading