scikit-rt / scikit-rt

Toolkit for analysis of radiotherapy data
https://scikit-rt.github.io/scikit-rt/
GNU General Public License v3.0
8 stars 3 forks source link

Converting nifti --> DICOM #14

Open poppynikou opened 3 months ago

poppynikou commented 3 months ago

I have a pipeline which works a little like:

  1. convert dicom--> nifti (this was done a while ago using a different library)

  2. do some processing and create synthetic CTs

  3. convert nifti --> dicom

  4. re-import into TPS as an additional image set for dose calcs

I am attempting to convert the nifti --> dicom using the scikit-rt library. I am using the write() function from the Image class. I am having two issues:

(1) I would like to use the header_source from the original dicom, so that the affine is kept and the voxel spacing etc are preserved. However, when I do this the TPS thinks that this image is the same file as the original image. I think this stems from the fact that the UIDs are copied over, so they are exactly the same. Is there of way of converting the image so that it is still identified as the same patient, but as a separate image set. (2) The nifti --> dicom conversion flips the image left to right. Is there a way of stopping this?

kh296 commented 3 months ago
  1. It would be useful to have a bit more information about the requirements. In particular:

    • Does your input NIfTI file correctly define the affine matrix? (If it does, then the image geometry should be correctly defined in the output DICOM without needing to specify header_source.)
    • When you load the output DICOM image to the TPS, do you need it to be linked to other data (e.g. RTSTRUCT data)?
    • How do you identify different images as relating to the same patient? Is this based on "Patient ID" or similar in the DICOM header, or is it based on UIDs (e.g. study UIDs).?
  2. Try forcing the image loaded from the NIfTI source to be represented as if loaded from a DICOM source:

    from skrt import Image
    im = Image("/path/to/nifti/source").astype("dcm")

    (See the documentation of Image.astype() for why NIfTI and DICOM representations are different.)

poppynikou commented 3 months ago

Hi - thank you for all your help ! I spent a lot of time working on this, and the problem can be solved if the original data is converted to a nifti using scikit-rt and then back to dicom using scikit-rt. It must have been some discrepancy in the way that the nifti is created using other libraries.

convert dicom--> nifti do some processing and create synthetic CTs convert nifti --> dicom

To import the data back in the TPS I found the only tags which had to match the original planning CT were the 'Patient Name' and 'Patient ID', which can be added manually to the dicom header afterwards creating it.