Skip to content

Error when segmentation consists of only one pixel #131

@ThomasBudd

Description

@ThomasBudd

Hi together,

I've encontered an openCV error in one case where only one voxel was annotated in a slice (full error log below).

I found the root of the error in the file image_helper.py in the function get_slice_mask_from_slice_contour_data. When there is only one annotated pixel, the line 275

polygon = np.array(polygon).squeeze()

reduces the polygon array to an array of size 2, but the cv.fillPoly needs the array to be of size n x 2 where n is the number of countour points in this slice (in this case n=1). I fixed this by adding

if polygon.ndim == 1:
        polygon = polygon[None]

just in the line below and now it works for me. Would you mind adding this to your repo?

Many thanks!

here is the full error log:

File ~/miniconda3/envs/torch_env/lib/python3.12/site-packages/spyder_kernels/py3compat.py:356 in compat_exec
exec(code, globals, locals)

File /import/H-HH-Laufwerk/thomas/lungenprojekte/Python/visual_eval/NILS/try_read_rtstruct.py:21
ccs += (i+1) * rtstruct.get_roi_mask_by_name(roi_name)

File ~/miniconda3/envs/torch_env/lib/python3.12/site-packages/rt_utils/rtstruct.py:113 in get_roi_mask_by_name
return image_helper.create_series_mask_from_contour_sequence(

File ~/miniconda3/envs/torch_env/lib/python3.12/site-packages/rt_utils/image_helper.py:247 in create_series_mask_from_contour_sequence
mask[:, :, i] = get_slice_mask_from_slice_contour_data(

File ~/miniconda3/envs/torch_env/lib/python3.12/site-packages/rt_utils/image_helper.py:280 in get_slice_mask_from_slice_contour_data
cv.fillPoly(img=slice_mask, pts = polygons, color = 1)

error: OpenCV(4.9.0) /io/opencv/modules/imgproc/src/drawing.cpp:2432: error: (-215:Assertion failed) p.checkVector(2, CV_32S) >= 0 in function 'fillPoly'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions