Skip to content

Commit fb95f25

Browse files
committed
fixed for subsegmentation and lapy+cc contour
1 parent 8dbf4c9 commit fb95f25

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

CorpusCallosum/fastsurfer_cc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def _set_help_sid(action):
180180
)
181181
parser.add_argument(
182182
"--contour_smoothing",
183-
type=float,
183+
type=int,
184184
default=5,
185185
help="Gaussian sigma for smoothing during contour detection. Higher values mean a smoother CC outline, at the "
186186
"cost of precision.",
@@ -877,6 +877,7 @@ def _orig2midslab_vox2vox(additional_context: int = 0) -> AffineMatrix4x4:
877877

878878
# save segmentation labels, this
879879
if sd.has_attribute("cc_segmentation"):
880+
sd.filename_by_attribute("cc_segmentation").parent.mkdir(exist_ok=True, parents=True)
880881
io_futures.append(thread_executor().submit(
881882
nib.save,
882883
nib.MGHImage(cc_fn_seg_labels, fsaverage_midslab_vox2ras, orig.header),
@@ -956,13 +957,15 @@ def _orig2midslab_vox2vox(additional_context: int = 0) -> AffineMatrix4x4:
956957

957958

958959
if sd.has_attribute("cc_mid_measures"):
960+
sd.filename_by_attribute('cc_mid_measures').parent.mkdir(exist_ok=True, parents=True)
959961
io_futures.append(thread_executor().submit(
960962
save_cc_measures_json,
961963
sd.filename_by_attribute('cc_mid_measures'),
962964
output_metrics_middle_slice | additional_metrics,
963965
))
964966

965967
if sd.has_attribute("cc_measures"):
968+
sd.filename_by_attribute("cc_measures").parent.mkdir(exist_ok=True, parents=True)
966969
io_futures.append(thread_executor().submit(
967970
save_cc_measures_json,
968971
sd.filename_by_attribute("cc_measures"),
@@ -972,7 +975,7 @@ def _orig2midslab_vox2vox(additional_context: int = 0) -> AffineMatrix4x4:
972975
# save lta to fsaverage space
973976

974977
if sd.has_attribute("upright_lta"):
975-
sd.filename_by_attribute("cc_mid_measures").parent.mkdir(exist_ok=True, parents=True)
978+
sd.filename_by_attribute("upright_lta").parent.mkdir(exist_ok=True, parents=True)
976979
logger.info(f"Saving LTA to fsaverage space: {sd.filename_by_attribute('upright_lta')}")
977980
io_futures.append(thread_executor().submit(
978981
write_lta,

CorpusCallosum/shape/contour.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,11 @@ def from_mask_and_acpc(
773773
_contour: Points2dType = skimage.measure.find_contours(cc_mask, level=0.5)[0]
774774

775775
# FIXME: maybe CCContour should just inherit from Polygon?
776+
# remove last, duplicate point
777+
_contour = _contour[:-1]
776778
polygon = lapy.polygon.Polygon(np.concatenate([np.zeros_like(_contour[:, :1]), _contour], axis=1), closed=True)
777779
polygon.smooth_laplace(n=contour_smoothing, inplace=True)
778-
polygon.resample(701, inplace=True)
779-
780+
polygon.resample(700, inplace=True)
780781
contour_ras = apply_affine(slice_vox2ras, polygon.points)
781782

782783
ac_pc_3d = np.concatenate([[[0], [0]], np.stack([ac_2d, pc_2d], axis=0)], axis=1) # (2, 3)

CorpusCallosum/shape/postprocessing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,10 @@ def make_subdivision_mask(
581581
coords_vox = np.stack(np.mgrid[0:1, 0:rows, 0:cols], axis=-1)
582582
coords_ras = apply_affine(vox2ras, coords_vox)
583583

584-
cc_labels_posterior_to_anterior = SUBSEGMENT_LABELS
584+
# Use only as many labels as needed based on the number of subdivisions
585+
# Number of regions = number of division lines + 1
586+
num_labels_needed = len(subdivision_segments) + 1
587+
cc_labels_posterior_to_anterior = SUBSEGMENT_LABELS[:num_labels_needed]
585588

586589
# Initialize with first segment label
587590
subdivision_mask = np.full(slice_shape, cc_labels_posterior_to_anterior[0], dtype=np.int32)

0 commit comments

Comments
 (0)