Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filling of rois when there are holes #53

Merged
merged 3 commits into from
Jul 20, 2022

Conversation

igorhlx
Copy link
Contributor

@igorhlx igorhlx commented Jun 8, 2022

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):
3521cb8d-e39d-471a-8c8c-a7eba1ed7a9e
And if only one label.
bad
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)
correct_figure
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 change assert 0.9619047619047619 >= 1.0)
  • unit test was expanded by one more shape (lower right on the image)
    two_holes_test
  • 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).

@igorhlx igorhlx changed the title Fix filling of rois with holes Fix filling of rois when there are holes Jun 10, 2022
asim-shrestha
asim-shrestha previously approved these changes Jul 20, 2022
Copy link
Contributor

@asim-shrestha asim-shrestha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic job, thank you for doing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants