Sikerdebaard / dcmrtstruct2nii

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

Allow optionally specifying Series Instance UID #25

Closed StellarStorm closed 2 years ago

StellarStorm commented 2 years ago

Hi @Sikerdebaard! I found that when there are dicoms with two different Series Instance UID values, non-image dicoms would sometimes be loaded and treated as images. For instance, in one dataset I'm using the RD.dcm has a different ID than the CT.dcm (although they do correspond in reality), and the dose structure was getting loaded as the image. Then the program would of course crash when trying to export the structures as it couldn't map them to the (non-)image. This allows the series ID to optionally be specified so that the correct images will be loaded.

Specifically:

Depending on whether you were using the CLI or the Python interface, the error messages looked like this:

CLI:

Working on mask RANDOM

  RuntimeError

  Exception thrown in SimpleITK Image_TransformPhysicalPointToIndex: d:\bld\libsimpleitk_1627514864077\work\code\common\src\sitkPimpleImageBase.hxx:201:
  sitk::ERROR: vector dimension mismatch

  at ~\Miniconda3\envs\tf2.3\lib\site-packages\SimpleITK\SimpleITK.py:3242 in TransformPhysicalPointToIndex
       3238│         Transform physical point to index
       3239│
       3240│
       3241│         """
    →  3242│         return _SimpleITK.Image_TransformPhysicalPointToIndex(self, point)
       3243│
       3244│     def TransformPhysicalPointToContinuousIndex(self, point):
       3245│
       3246│         TransformPhysicalPointToContinuousIndex(Image self, VectorDouble point) -> VectorDouble

Python:

Traceback (most recent call last):
  File "dcmrtstruct2nii\dcmrtstruct2nii\adapters\convert\rtstructcontour2mask.py", line 40, in convert
    world_coords = dicom_image.TransformPhysicalPointToContinuousIndex((coordinates['x'][index], coordinates['y'][index], coordinates['z'][index]))
  File "Miniconda3\envs\tf2.3\lib\site-packages\SimpleITK\SimpleITK.py", line 3253, in TransformPhysicalPointToContinuousIndex
    return _SimpleITK.Image_TransformPhysicalPointToContinuousIndex(self, point)
RuntimeError: Exception thrown in SimpleITK Image_TransformPhysicalPointToContinuousIndex: d:\bld\libsimpleitk_1627514864077\work\code\common\src\sitkPimpleImageBase.hxx:237:
sitk::ERROR: vector dimension mismatch

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "dcmrtstruct2nii\dcmrtstruct2nii\facade\dcmrtstruct2nii.py", line 81, in dcmrtstruct2nii
    mask = dcm_patient_coords_to_mask.convert(rtstruct['sequence'], dicom_image, mask_background_value, mask_foreground_value)
  File "dcmrtstruct2nii\dcmrtstruct2nii\adapters\convert\rtstructcontour2mask.py", line 42, in convert
    world_coords = dicom_image.TransformPhysicalPointToIndex(
  File "Miniconda3\envs\tf2.3\lib\site-packages\SimpleITK\SimpleITK.py", line 3242, in TransformPhysicalPointToIndex
    return _SimpleITK.Image_TransformPhysicalPointToIndex(self, point)
RuntimeError: Exception thrown in SimpleITK Image_TransformPhysicalPointToIndex: d:\bld\libsimpleitk_1627514864077\work\code\common\src\sitkPimpleImageBase.hxx:201:
sitk::ERROR: vector dimension mismatch

Cheers!

Sikerdebaard commented 2 years ago

That is an excellent contribution. Thanks for that! :)

I'll see if I can release a new version with these improvements later this week.

Sikerdebaard commented 2 years ago

Had to fix the unit tests so it took a bit longer, but it's live now. pip install --upgrade dcmrtstruct2nii==2

Thanks again for this excellent contribution. :)