Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Dear everyone,
A thing that has bugged me when using this (otherwise wonderful) package, is the jagged, unsmooth and a bit too small contours which are returned, when converting binary masks into rtss.
In this PR I propose implementation of how smoothing can be added as an option. Essentially, it is iterations of applying the following filters.
How to run it
All you have to do is to run the usual add_roi() with another parameter:
Furthermore, you can tweak the smoothing by parsing a dict with parameters. The setup is a little curious, and there is room for improvement, but essentially it looks like this:
The above dict can be used by doing:
I have added the possibility to choose running the filters in either 3d or 2d. I have done most parameter tuning in 2d, and have come up with two sets, which works well, so if
Furthermore, this is a nice entry point to add other smoothing algorithms like:
Other things in the code
In order to be able to add upscaled masks, there is a check in rtstruct.addroi():
This determines the scale in X, Y which will then be taken into account in image_helper.find_mask_contours():
Show case
![GroundTruth in dicom and nifti](https://private-user-images.githubusercontent.com/22869237/246035103-68354bfb-c30f-438b-8951-bcba43d352cd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk3ODEyOTksIm5iZiI6MTcxOTc4MDk5OSwicGF0aCI6Ii8yMjg2OTIzNy8yNDYwMzUxMDMtNjgzNTRiZmItYzMwZi00MzhiLTg5NTEtYmNiYTQzZDM1MmNkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjMwVDIwNTYzOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQ2NmQ0MGZhOGNjZjljZDU3MWIzZTAxOTIyZjc2MzAzZjNlNmQ3ODc5OGM3Y2JmNGMxNzk5NmIxZGYxZWYwYWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.1Cgc1n5s90_BIbm-MP8WCdp71GBqTaqx4oRoxfcis0w)
Because I work with clinical data, I do not show the underlying images. It does not matter for the impression, I guess.
Below is a image where red is the initial dicom rtss and in green is the same converted to binary nifti masks in CT-grid.
Converting the green nifti directly back to dicom rtss with the current main branch gives this, where red is ground truth and blue is the converted rtss:
![Vanilla vs GT](https://private-user-images.githubusercontent.com/22869237/246035497-f1fd132d-31e9-40e1-bb25-e19dd4c61210.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk3ODEyOTksIm5iZiI6MTcxOTc4MDk5OSwicGF0aCI6Ii8yMjg2OTIzNy8yNDYwMzU0OTctZjFmZDEzMmQtMzFlOS00MGUxLWJiMjUtZTE5ZGQ0YzYxMjEwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjMwVDIwNTYzOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTA5OTdiOWEzOTdkYTQxNTIxNTQ4OTRmYmJjNTc2YjQ1Yjc2NjM4MzE4NTMxNjEwMmRmYjgwNzgwMzhkMDQ0OTAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.gYI3p44V-8CYxpdGnPbLFRfb14XkRTt48wJvjQ4Za2Y)
With default parameters of this PR the same conversion yields the following, where red is ground truth and blue is conversion:
![Dicom GT and smooth consversion](https://private-user-images.githubusercontent.com/22869237/246039967-55a38dca-160d-4c19-85b1-d0ea17588d42.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk3ODEyOTksIm5iZiI6MTcxOTc4MDk5OSwicGF0aCI6Ii8yMjg2OTIzNy8yNDYwMzk5NjctNTVhMzhkY2EtMTYwZC00YzE5LTg1YjEtZDBlYTE3NTg4ZDQyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjMwVDIwNTYzOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTUwNGUxMWVjOWQ3OWRjOGI1MjE0YmRmYWNlYTQ4ZWU3MTk5NzBjMTgxMjUwMWYxOTdlYWMzOWNhY2RhYmVmN2MmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.b34dHMS8X4V3tE0RLcqn404dK9F7ZrhOk8rfdRpxgJs)
Purpose of the PR
I do not know what the maintainers thinks about implementing this into the standard package, but to me and my work, well-working smoothing is a game-changer. I hope we can discuss if other algorithms should be implemented too or if the interface should look different.
Looking forward to hear your thoughts,
Mathis