Sikerdebaard / dcmrtstruct2nii

DICOM RT-Struct to mask
MIT License
91 stars 27 forks source link

dcmrtstruct2nii(1.0.18) converting dicom rt to nii occured KeyError 'sequence' #4

Closed fcjxxl closed 4 years ago

fcjxxl commented 4 years ago

RectumTest.zip Data attached

dcmrtstruct2nii convert -r {rs_file_path} -d {ct_file_dir} -o {output_dir}
Working on mask Ref
Skipping unnamed contour, unsupported type: POINT
Working on mask Iso
Skipping unnamed contour, unsupported type: POINT
Working on mask GTV
Working on mask GTVnd
Working on mask CTV
Working on mask CTV1

  KeyError

  'sequence'

  at .pyenv/versions/3.6.9/lib/python3.6/site-packages/dcmrtstruct2nii/facade/dcmrtstruct2nii.py:75 in dcmrtstruct2nii
      71|     for rtstruct in rtstructs:
      72|         if len(structures) == 0 or rtstruct['name'] in structures:
      73|             logging.info('Working on mask {}'.format(rtstruct['name']))
      74|             try:
    > 75|                 mask = dcm_patient_coords_to_mask.convert(rtstruct['sequence'], dicom_image, mask_background_value, mask_foreground_value)
      76|             except ContourOutOfBoundsException:
      77|                 logging.warning(f'Structure {rtstruct["name"]} is out of bounds, ignoring contour!')
      78|                 continue
      79| 
dlabella29 commented 4 years ago

I have the exact same issue. Please let me know if you or anyone has found a solution.

Sikerdebaard commented 4 years ago

Most likely this occurs because no 'ContourSequence' is found for a specific contour (within the list ROIContourSequence) in the RTStruct.

If this is the case this check will probably fail so that the 'sequence'-key is not available: https://github.com/Sikerdebaard/dcmrtstruct2nii/blob/master/dcmrtstruct2nii/adapters/input/contours/rtstructinputadapter.py#L54

dlabella29 commented 4 years ago

thanks for the help!

for future reference...

I added in this try: except: statement to dcmrtstruct2nii.py line 76 and it worked.

        try:
            rtstruct['sequence']
            try:
                mask = dcm_patient_coords_to_mask.convert(rtstruct['sequence'], dicom_image, mask_background_value, mask_foreground_value)
            except ContourOutOfBoundsException:
                logging.warning(f'Structure {rtstruct["name"]} is out of bounds, ignoring contour!')
                continue
        except:
            continue
black0017 commented 4 years ago

@dlabella29 I tried it and it seems to work! It would be nice to add this in the repo @Sikerdebaard .

Sikerdebaard commented 4 years ago

A fix was added to the new 1.0.19 release and was validated against the example image from @fcjxxl. You can upgrade using pip install --upgrade dcmrtstruct2nii==1.0.19