Sikerdebaard / dcmrtstruct2nii

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

Bugfix/continuous index #10

Closed thomas-albrecht closed 3 years ago

thomas-albrecht commented 3 years ago

Hi, happy new year!

When upgrading to scikit-image 0.18 I found that the behaviour of dcmrtstruct2nii changed, and when debugging I added some improvements that I would like to share back.

  1. Going from sickit image 0.17 to 0.18, they changed the method that determines if a pixel is inside a polygon for cases when the pixel is exactly on the border of the polygon. This caused the change in behaviour of dcmrtstruct2nii.
  2. This happened consistently with dcmrtstruct2nii, even in a test where I constructed a polygon that is not exactly on the pixels. I noticed that the converter uses ITK's function TransformPhysicalPointToIndex to map the RTStruct's physical coordinates to pixel coordinates. However, this version always returns integer indices, which is why the polygon always coincides with pixel coordinates.
  3. In my opinion the function TransformPhysicalPointToContinuousIndex is the one to use here as it allows for non-integer indices. To make sure the z coordinate is always the correct integer, I added a round as well. With this change, the result stays the same for scikit-image 0.17 and 0.18 for my tests.
  4. When looking at the changes of scikit-image, I found that since version 0.17 it also includes a function polygon2mask, which makes the function _poly2mask superfluous. I used that function but I had to flip the shape to make it work correctly. I suspect that the shape should have been flipped anyway in the _poly2mask because of the old problem that ITK and numpy reverse the dimensions.

I did not find any tests in the repository. So before merging you may have to run your tests to make sure everything works correctly.

Sikerdebaard commented 3 years ago

Thanks for this! I haven't forgotten about this PR, but it's been bussy. I'll get to testing this code as soon as possible™ and then merge your code into a new release if everything works as expected.