nnUNet icon indicating copy to clipboard operation
nnUNet copied to clipboard

DICOM to nii nnUNet format

Open anabm07 opened this issue 2 years ago • 3 comments

Hi all,

I am surprised I did not see this in the FAQ or in any issue before (sorry if this info exists but I could not find it): Is there any easy way or already available functions to convert from DICOM to nnUNet nifti format for the training/test data? I have explored dicom2nifti library but this is only for the CT, and not the RTSTRUCT. What do you recommend?

Best, Ana

anabm07 avatar Jun 28 '22 09:06 anabm07

It's easy to do this: import SimpleITK as sitk

step1:read data from dcm

        series_file_names = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(dcm_dir)
        series_reader = sitk.ImageSeriesReader()
        series_reader.SetFileNames(series_file_names)
        image3D = series_reader.Execute()

step2: save as nii.gz

        save_img_file  = "***.nii.gz"
        sitk.WriteImage(image3D, save_img_file, True)

        

BigPandaCPU avatar Jun 29 '22 09:06 BigPandaCPU

Hello thanks a lot!

I have also found out a codalab notebook where they use Plastimatch, I guess this is another good alternative. Just in case someone need it:

https://github.com/RSNA/AI-Deep-Learning-Lab-2021/blob/main/sessions/tcia-idc/RSNA_2021_IDC_and_TCIA.ipynb

Ana

anabm07 avatar Jun 29 '22 12:06 anabm07

@BigPandaCPU I am just trying your code and I see that it is to convert the CTs. My question was about converting the RTSTRUCTs, do you have a couple of lines to convert the RTSTRUCT with simple ITK?

anabm07 avatar Jul 04 '22 16:07 anabm07

Hey there, converting file formats to something that is interpretable by nnU-Net is not within the scopeof nnU-Net (how could it be?), so I cannot help you here. I will close this issue, but please fell free to continue the discussion.

@anabm07 do you know how to get a numpy array from your RTSTRUCT? If so then exporting that to nifti should be no problem

FabianIsensee avatar Aug 23 '22 10:08 FabianIsensee