When drawing, sometimes multiple contours are found for a single mask, but the code expects to encounter only a single contour.
For example:
|
contours = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) |
|
pvc, pvr = contours[-2][0][:,0].T |
and
|
contours = cv2.findContours(mask, cv2.RETR_EXTERNAL, |
|
cv2.CHAIN_APPROX_NONE) |
|
pvc, pvr = contours[-2][0][:,0].T |
and in 3d GUI:
|
contours = cv2.findContours(mask, cv2.RETR_EXTERNAL, |
|
cv2.CHAIN_APPROX_NONE) |
|
pvc, pvr = contours[-2][0].squeeze().T |
and here:
|
contours = cv2.findContours(mask, cv2.RETR_EXTERNAL, |
|
cv2.CHAIN_APPROX_NONE) |
|
pvc, pvr = contours[-2][0].squeeze().T |
and also in merge_cells():
|
contours = cv2.findContours(mask, cv2.RETR_EXTERNAL, |
|
cv2.CHAIN_APPROX_NONE) |
|
pvc, pvr = contours[-2][0].squeeze().T |
This error manifests when there is a small hole in a mask that is being overlapped that is right on the edge of a mask, (see image below). Presumabely there are also other edge cases when this occurs. No errors are ever seen because the add_mask() functions are called in the overriden Qt virtual methods (keyPressEvent, mouseClickEvent) which is, apparently by design.
Example breaking mask (mask is on the left with a single missing interior pixel):

Two changes should be made:
- Handle the edge case for when multiple contours are found.
- Implement more robust drawing logic that will allow drawing to fail gracefully.
When drawing, sometimes multiple contours are found for a single mask, but the code expects to encounter only a single contour.
For example:
cellpose/cellpose/gui/gui.py
Lines 1574 to 1575 in 94ae120
and
cellpose/cellpose/gui/gui.py
Lines 1589 to 1591 in 94ae120
and in 3d GUI:
cellpose/cellpose/gui/gui3d.py
Lines 292 to 294 in 94ae120
and here:
cellpose/cellpose/gui/gui3d.py
Lines 308 to 310 in 94ae120
and also in
merge_cells():cellpose/cellpose/gui/gui.py
Lines 1318 to 1320 in 94ae120
This error manifests when there is a small hole in a mask that is being overlapped that is right on the edge of a mask, (see image below). Presumabely there are also other edge cases when this occurs. No errors are ever seen because the
add_mask()functions are called in the overriden Qt virtual methods (keyPressEvent,mouseClickEvent) which is, apparently by design.Example breaking mask (mask is on the left with a single missing interior pixel):

Two changes should be made: