@@ -507,7 +507,9 @@ def transcode_dicom_to_htj2k(
507507 has_pixel_data = hasattr (ds , "PixelData" ) and ds .PixelData is not None
508508 if ts_str in skip_transfer_syntaxes or not has_pixel_data :
509509 skip_batch .append (idx )
510- logger .info (f" Skipping { os .path .basename (batch_in [idx ])} (Transfer Syntax: { ts_str } , has_pixel_data: { has_pixel_data } )" )
510+ logger .info (
511+ f" Skipping { os .path .basename (batch_in [idx ])} (Transfer Syntax: { ts_str } , has_pixel_data: { has_pixel_data } )"
512+ )
511513 continue
512514
513515 assert has_pixel_data , f"DICOM file { os .path .basename (batch_in [idx ])} does not have a PixelData member"
@@ -1049,9 +1051,13 @@ def convert_single_frame_dicom_series_to_multiframe(
10491051 # Save ImageOrientationPatient and ImagePositionPatient BEFORE creating output_ds
10501052 # The shallow copy + delattr will affect the original datasets objects
10511053 # 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-
1054+ original_image_orientation = (
1055+ datasets [0 ].ImageOrientationPatient if hasattr (datasets [0 ], "ImageOrientationPatient" ) else None
1056+ )
1057+ original_image_positions = [
1058+ ds .ImagePositionPatient if hasattr (ds , "ImagePositionPatient" ) else None for ds in datasets
1059+ ]
1060+
10551061 # Create SIMPLE multi-frame DICOM file (like the user's example)
10561062 # Use first dataset as template, keeping its metadata
10571063 logger .info (f" Creating simple multi-frame DICOM from { total_frame_count } frames..." )
@@ -1108,19 +1114,28 @@ def convert_single_frame_dicom_series_to_multiframe(
11081114 # CRITICAL: Remove top-level ImagePositionPatient and ImageOrientationPatient
11091115 # Working files (that display correctly in OHIF MPR) have NEITHER at top level
11101116 # These should ONLY exist in functional groups for Enhanced CT
1111-
1117+
11121118 if hasattr (output_ds , "ImagePositionPatient" ):
11131119 delattr (output_ds , "ImagePositionPatient" )
11141120 logger .info (f" ✓ Removed top-level ImagePositionPatient (use per-frame only)" )
1115-
1121+
11161122 if hasattr (output_ds , "ImageOrientationPatient" ):
11171123 delattr (output_ds , "ImageOrientationPatient" )
11181124 logger .info (f" ✓ Removed top-level ImageOrientationPatient (use SharedFunctionalGroupsSequence only)" )
11191125 # Set correct SOPClassUID for multi-frame (Enhanced/Multiframe) conversion
11201126 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
1127+ "1.2.840.10008.5.1.4.1.1.2" : (
1128+ "1.2.840.10008.5.1.4.1.1.2.1" ,
1129+ "Enhanced CT Image Storage" ,
1130+ ), # CT -> Enhanced CT
1131+ "1.2.840.10008.5.1.4.1.1.4" : (
1132+ "1.2.840.10008.5.1.4.1.1.4.1" ,
1133+ "Enhanced MR Image Storage" ,
1134+ ), # MR -> Enhanced MR
1135+ "1.2.840.10008.5.1.4.1.1.6.1" : (
1136+ "1.2.840.10008.5.1.4.1.1.3.1" ,
1137+ "Ultrasound Multi-frame Image Storage" ,
1138+ ), # US -> Ultrasound Multi-frame
11241139 }
11251140
11261141 original_sopclass = getattr (datasets [0 ], "SOPClassUID" , None )
@@ -1186,7 +1201,9 @@ def convert_single_frame_dicom_series_to_multiframe(
11861201 else :
11871202 # If missing, use default (0,0,frame_idx * spacing)
11881203 # 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
1204+ default_spacing = (
1205+ float (output_ds .SpacingBetweenSlices ) if hasattr (output_ds , "SpacingBetweenSlices" ) else 1.0
1206+ )
11901207 plane_pos_item .ImagePositionPatient = [0.0 , 0.0 , frame_idx * default_spacing ]
11911208 logger .warning (f" Frame { frame_idx } missing ImagePositionPatient, using default" )
11921209 frame_item .PlanePositionSequence = Sequence ([plane_pos_item ])
0 commit comments