Skip to content

Commit 83bbd0e

Browse files
committed
The fixes ensure:
✅ PlanePositionSequence added to every frame (with default if missing) ✅ PlaneOrientationSequence added to SharedFunctionalGroupsSequence (with standard axial if missing) Both are MANDATORY for Enhanced CT multi-frame files to enable MPR in OHIF. Now regenerate your multi-frame files with the updated script and the MPR button should be active
1 parent 4f51a22 commit 83bbd0e

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

monailabel/datastore/utils/convert_htj2k.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,11 +1162,17 @@ def convert_single_frame_dicom_series_to_multiframe(
11621162
frame_item = DicomDataset()
11631163

11641164
# PlanePositionSequence - ImagePositionPatient for this frame
1165-
# This is REQUIRED - each frame needs its own position
1165+
# This is MANDATORY for Enhanced CT multi-frame
1166+
plane_pos_item = DicomDataset()
11661167
if hasattr(ds_frame, "ImagePositionPatient"):
1167-
plane_pos_item = DicomDataset()
11681168
plane_pos_item.ImagePositionPatient = ds_frame.ImagePositionPatient
1169-
frame_item.PlanePositionSequence = Sequence([plane_pos_item])
1169+
else:
1170+
# If missing, use default (0,0,frame_idx * spacing)
1171+
# This shouldn't happen for valid CT series, but ensures MPR compatibility
1172+
default_spacing = float(output_ds.SpacingBetweenSlices) if hasattr(output_ds, 'SpacingBetweenSlices') else 1.0
1173+
plane_pos_item.ImagePositionPatient = [0.0, 0.0, frame_idx * default_spacing]
1174+
logger.warning(f" Frame {frame_idx} missing ImagePositionPatient, using default")
1175+
frame_item.PlanePositionSequence = Sequence([plane_pos_item])
11701176

11711177
# CRITICAL: Do NOT add per-frame PlaneOrientationSequence!
11721178
# PlaneOrientationSequence should ONLY be in SharedFunctionalGroupsSequence
@@ -1191,11 +1197,16 @@ def convert_single_frame_dicom_series_to_multiframe(
11911197
# This defines attributes that are common to ALL frames
11921198
shared_item = DicomDataset()
11931199

1194-
# PlaneOrientationSequence - same for all frames
1200+
# PlaneOrientationSequence - MANDATORY for Enhanced CT multi-frame
1201+
shared_orient_item = DicomDataset()
11951202
if hasattr(datasets[0], "ImageOrientationPatient"):
1196-
shared_orient_item = DicomDataset()
11971203
shared_orient_item.ImageOrientationPatient = datasets[0].ImageOrientationPatient
1198-
shared_item.PlaneOrientationSequence = Sequence([shared_orient_item])
1204+
else:
1205+
# If missing, use standard axial orientation
1206+
# This ensures MPR button is enabled in OHIF
1207+
shared_orient_item.ImageOrientationPatient = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]
1208+
logger.warning(f" Source files missing ImageOrientationPatient, using standard axial orientation")
1209+
shared_item.PlaneOrientationSequence = Sequence([shared_orient_item])
11991210

12001211
# PixelMeasuresSequence - pixel spacing and slice thickness
12011212
if hasattr(datasets[0], "PixelSpacing") or hasattr(datasets[0], "SliceThickness"):

0 commit comments

Comments
 (0)