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
unit test expects IOU=1.0, i.e 100% accuracy (it, expectedly, failed when I made only this changeassert 0.9619047619047619 >= 1.0)
unit test was expanded by one more shape (lower right on the image)
merge get_slice_mask_from_slice_contour_data and get_contour_fill_mask (removing the later)
create a list of polygons in a correct format (and geometry) and pass it to fillPoly
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).
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
And if only one label.
And a correct one (original image on the left with polygons from
Passing a list/tuple to
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):findContours
, and correct reconstructed map using round trip with only openCV's functions)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).