Sikerdebaard / dcmrtstruct2nii

DICOM RT-Struct to mask
MIT License
93 stars 26 forks source link

Added support for holes with xor logic #37

Closed mathiser closed 1 year ago

mathiser commented 1 year ago

Dear Thomas, Here comes a pull request to support holes in contours. It is a simple xor logic when overriding the sequences. I have added my test images below, showing that it works for complex structures.

In DICOM: dots

In Nifti: nifti

A wave in Nifti Screenshot_20230125_113459

It does not work if a contour goes all the way the the edge. It seems that this is a problem which also exist with the current code. I'm opening this as an issue later today.

Apart from this update I have suggested to move the sitk.GetImageFromArray()-call to the very end of the function. This call is notoriously slow, and is called redundantly many times now.

Kind regards, Mathis Rasmussen

mathiser commented 1 year ago

I have opened #39 in relation to the edge issue. I'm just showing here, what the conversion from #39 looks like with the method presented in this PR.

Dicom: faildicom

Nifti Screenshot_20230125_133810

Sikerdebaard commented 1 year ago

@mathiser this looks like an excellent contribution to this tool and it would probably warrant a new version release. I will probably add a flag so that others can use the old behavior just in case. I think it would be good to have this as the new default behavior.

Before I add this new logic, would you mind sharing the example RT-Structs so that they can be included in the unit tests? If the RT-Structs are not available in a public server already then perhaps it could be possible to upload them to a separate GitHub repository?

mathiser commented 1 year ago

Hi @Sikerdebaard, Sorry for the latency. I'll check if I can share the RTSTRUCT today. I'm a little in doubt if there are any sensitive tags in there. If not, do you then have some scan which you use for testing in other parts of the code that I can use? I can easily produce a new RTSTRUCT for testing purposes.

Mathis

Sikerdebaard commented 1 year ago

If not, do you then have some scan which you use for testing in other parts of the code that I can use? I can easily produce a new RTSTRUCT for testing purposes.

The current unit tests use the stwstrategyhn1 dataset on the bmia xnat.

Let me know if you need help downloading from this server.

https://xnat.bmia.nl/app/template/XDATScreen_report_xnat_projectData.vm/search_element/xnat:projectData/search_field/xnat:projectData.ID/search_value/stwstrategyhn1

mathiser commented 1 year ago

Brilliant. I'm just gonna select the first one and redo the examples. I'll send it over later today.

mathiser commented 1 year ago

I made these examples on the CT of HN1004_20190403_CT. I attached conversions of both the original method and new proposed method - including a contour which fails in both methods. The examples are made in Slicer. I suspect the reason for the failures is that contour coordinates are not put at the edge if the brush exits the image frame. It may be different in other TPSs.

slicerexport.zip

Kind regards, Mathis