Skip to content

Commit

Permalink
Fix: Now the IOP and IPP are written for RGB DICOM images
Browse files Browse the repository at this point in the history
- The entire code base is shitty - but hey it works!
  • Loading branch information
LalithShiyam committed Apr 17, 2024
1 parent 9f8486b commit ffd9721
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions nifti2dicom/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,14 @@ def write_rgb_dicom_from_nifti(nifti_file_path, reference_dicom_series, output_d

metadata = get_metadata_from_dicom_series(reference_dicom_series)

# Load the dicom series

dicom_reference_img = load_image(reference_dicom_series, 'dicom')

rgb_img = sitk.ReadImage(nifti_file_path)
# set rgb_img origin and direction to match the dicom series
rgb_img.SetOrigin(dicom_reference_img.GetOrigin())
rgb_img.SetDirection(dicom_reference_img.GetDirection())
arr = sitk.GetArrayFromImage(rgb_img)
arr = arr[:, :, :, :3] # Ensure only RGB, no alpha

Expand All @@ -213,6 +220,11 @@ def write_rgb_dicom_from_nifti(nifti_file_path, reference_dicom_series, output_d
for i, slice_array in enumerate(arr, start=1):
ds = create_rgb_dicom_from_slice(slice_array, series_tag_values, metadata, i)
dicom_filename = os.path.join(output_directory, f"slice_{i}.dcm")
ds.ImageOrientationPatient = metadata.ImageOrientationPatient
ds.ImagePositionPatient = list(rgb_img.TransformIndexToPhysicalPoint((0, 0, i)))
ds.PatientName = metadata.PatientName
ds.PatientID = metadata.PatientID
ds.PatientBirthDate = metadata.PatientBirthDate
write_file(dicom_filename, ds, write_like_original=False)
progress.update(task, advance=1, description=f"[white] Writing RGB DICOM slices... [{i}/{total_slices}]")

Expand Down

0 comments on commit ffd9721

Please sign in to comment.