Fix filling of rois when there are holes #53
Merged
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.
First of all thanks for this great package to deal with RT structures.
Description of PR
As stated in the "How it works" rt-utils is not handling holes perfectly. In this PR I am trying to fix this.
Currently, rt-utils handle multiple polygons of one slice by adding them separately and subtracting/inverting if it is a hole this results in more subtraction then it should be (as polygon itself is included when using
cv.fillPoly
).Example of this effect (note original image looks more like the following image below):
With multiple ROIs (original on the left and round trip loaded on the left):
And if only one label.
And a correct one (original image on the left with polygons from
findContours
, and correct reconstructed map using round trip with only openCV's functions)Passing a list/tuple to
fillPoly
solves this issue as it will fill the mask correctly so there is no need for handling each contour manually, it just needs to be in a correct format. In this PR I am doing that.Please, let me know if the coding style suits your coding style, or if I need to change anything else.
Specific Changes
assert 0.9619047619047619 >= 1.0
)get_slice_mask_from_slice_contour_data
andget_contour_fill_mask
(removing the later)Testing
Run pytest after you install this package.
This will, among other tests, check the round trip with the new test shape and see if it is perfect (IOU==1).