qurit / rt-utils

A minimal Python library to facilitate the creation and manipulation of DICOM RTStructs.
MIT License
191 stars 56 forks source link

Fix filling of rois when there are holes #53

Closed igorhlx closed 2 years ago

igorhlx commented 2 years ago

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

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).