cv.fillPoly() exception when running rtstruct.get_roi_mask_by_name
@plesqui is already working on this.
Since Jul 31, 2023.
- Dominant language
- Python
- Stars
- 256
- Forks
- 75
- PR merge metrics
- No merged PRs in 30d
Description
Hi there,
For my project, I've got multiple patients and I've generated an individual RTStructBuilder object per patient. Within the RTStructBuilder objects I have multiple ROIs (>50).
I am trying to use the rtstruct.get_roi_mask_by_name function to generate binary masks of each region, however I am getting an exception within image_helper.py line 278.
The exception occurs with some – but not all – of the ROIs within the RTStructBuilder object.
For instance, it will work with region1, e.g.:
mask = rtstruct.get_roi_mask_by_name('region1')
whereas say region2 will fail with the following error message:
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1483, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/tr17/Library/Application Support/JetBrains/PyCharm2021.2/scratches/load_rt.py", line 123, in <module>
mask = rtstruct_TS.get_roi_mask_by_name('lung_upper_lobe_right')
File "/Users/tr17/venv/prague/lib/python3.9/site-packages/rt_utils/rtstruct.py", line 113, in get_roi_mask_by_name
return image_helper.create_series_mask_from_contour_sequence(
File "/Users/tr17/venv/prague/lib/python3.9/site-packages/rt_utils/image_helper.py", line 247, in create_series_mask_from_contour_sequence
mask[:, :, i] = get_slice_mask_from_slice_contour_data(
File "/Users/tr17/venv/prague/lib/python3.9/site-packages/rt_utils/image_helper.py", line 281, in get_slice_mask_from_slice_contour_data
cv.fillPoly(img=slice_mask, pts = polygons, color = 1)
cv2.error: OpenCV(4.7.0) /Users/xperience/GHA-OCV-Python/_work/opencv-python/opencv-python/opencv/modules/imgproc/src/drawing.cpp:2402: error: (-215:Assertion failed) p.checkVector(2, CV_32S) >= 0 in function 'fillPoly'
I've looked up the fillPoly error online and there are various posts about casting as int32, but I think you are already doing that properly.
I'm a bit stuck... much appreciated if you can help. Thanks in advance.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.