@@ -1049,9 +1049,13 @@ def convert_single_frame_dicom_series_to_multiframe(
10491049 # Save ImageOrientationPatient and ImagePositionPatient BEFORE creating output_ds
10501050 # The shallow copy + delattr will affect the original datasets objects
10511051 # Save these values now so we can use them in functional groups later
1052- original_image_orientation = datasets [0 ].ImageOrientationPatient if hasattr (datasets [0 ], "ImageOrientationPatient" ) else None
1053- original_image_positions = [ds .ImagePositionPatient if hasattr (ds , "ImagePositionPatient" ) else None for ds in datasets ]
1054-
1052+ original_image_orientation = (
1053+ datasets [0 ].ImageOrientationPatient if hasattr (datasets [0 ], "ImageOrientationPatient" ) else None
1054+ )
1055+ original_image_positions = [
1056+ ds .ImagePositionPatient if hasattr (ds , "ImagePositionPatient" ) else None for ds in datasets
1057+ ]
1058+
10551059 # Create SIMPLE multi-frame DICOM file (like the user's example)
10561060 # Use first dataset as template, keeping its metadata
10571061 logger .info (f" Creating simple multi-frame DICOM from { total_frame_count } frames..." )
@@ -1108,19 +1112,28 @@ def convert_single_frame_dicom_series_to_multiframe(
11081112 # CRITICAL: Remove top-level ImagePositionPatient and ImageOrientationPatient
11091113 # Working files (that display correctly in OHIF MPR) have NEITHER at top level
11101114 # These should ONLY exist in functional groups for Enhanced CT
1111-
1115+
11121116 if hasattr (output_ds , "ImagePositionPatient" ):
11131117 delattr (output_ds , "ImagePositionPatient" )
11141118 logger .info (f" ✓ Removed top-level ImagePositionPatient (use per-frame only)" )
1115-
1119+
11161120 if hasattr (output_ds , "ImageOrientationPatient" ):
11171121 delattr (output_ds , "ImageOrientationPatient" )
11181122 logger .info (f" ✓ Removed top-level ImageOrientationPatient (use SharedFunctionalGroupsSequence only)" )
11191123 # Set correct SOPClassUID for multi-frame (Enhanced/Multiframe) conversion
11201124 sopclass_map = {
1121- "1.2.840.10008.5.1.4.1.1.2" : ("1.2.840.10008.5.1.4.1.1.2.1" , "Enhanced CT Image Storage" ), # CT -> Enhanced CT
1122- "1.2.840.10008.5.1.4.1.1.4" : ("1.2.840.10008.5.1.4.1.1.4.1" , "Enhanced MR Image Storage" ), # MR -> Enhanced MR
1123- "1.2.840.10008.5.1.4.1.1.6.1" : ("1.2.840.10008.5.1.4.1.1.3.1" , "Ultrasound Multi-frame Image Storage" ), # US -> Ultrasound Multi-frame
1125+ "1.2.840.10008.5.1.4.1.1.2" : (
1126+ "1.2.840.10008.5.1.4.1.1.2.1" ,
1127+ "Enhanced CT Image Storage" ,
1128+ ), # CT -> Enhanced CT
1129+ "1.2.840.10008.5.1.4.1.1.4" : (
1130+ "1.2.840.10008.5.1.4.1.1.4.1" ,
1131+ "Enhanced MR Image Storage" ,
1132+ ), # MR -> Enhanced MR
1133+ "1.2.840.10008.5.1.4.1.1.6.1" : (
1134+ "1.2.840.10008.5.1.4.1.1.3.1" ,
1135+ "Ultrasound Multi-frame Image Storage" ,
1136+ ), # US -> Ultrasound Multi-frame
11241137 }
11251138
11261139 original_sopclass = getattr (datasets [0 ], "SOPClassUID" , None )
@@ -1186,7 +1199,9 @@ def convert_single_frame_dicom_series_to_multiframe(
11861199 else :
11871200 # If missing, use default (0,0,frame_idx * spacing)
11881201 # This shouldn't happen for valid CT series, but ensures MPR compatibility
1189- default_spacing = float (output_ds .SpacingBetweenSlices ) if hasattr (output_ds , 'SpacingBetweenSlices' ) else 1.0
1202+ default_spacing = (
1203+ float (output_ds .SpacingBetweenSlices ) if hasattr (output_ds , "SpacingBetweenSlices" ) else 1.0
1204+ )
11901205 plane_pos_item .ImagePositionPatient = [0.0 , 0.0 , frame_idx * default_spacing ]
11911206 logger .warning (f" Frame { frame_idx } missing ImagePositionPatient, using default" )
11921207 frame_item .PlanePositionSequence = Sequence ([plane_pos_item ])
0 commit comments