leaf-image-segmentation
leaf-image-segmentation copied to clipboard
Crash on flood fill
Traceback (most recent call last):
File "leaf-image-segmentation/segment.py", line 162, in <module>
segment_leaf(os.path.join(base_folder, file), filling_mode, smooth, args.marker_intensity)
File "leaf-image-segmentation/segment.py", line 66, in segment_leaf
select_largest_obj(bin_image, fill_mode=filling_mode,
File "leaf-image-segmentation/background_marker.py", line 229, in select_largest_obj
cv2.floodFill(img_floodfill, mask_, seedPoint=bkg_seed,
cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-ms668fyv/opencv/modules/imgproc/src/floodfill.cpp:509: error: (-211:One of the arguments' values is out of range) Seed point is outside of image in function 'floodFill'
Image:
Adding:
def clamp(n, smallest, largest):
return max(smallest, min(n, largest))
bkg_seed = (clamp(bkg_seed[0], 0, img_bin.shape[1] - 1), clamp(bkg_seed[1], 0, img_bin.shape[0] - 1))
to line 220 of background_marker.py fixes it.
This issue is probably caused by the inconsistent order of row and col in numpy and cv2. One simple fix is
replacing line 229 of background_marker.py
cv2.floodFill(img_floodfill, mask_, seedPoint=bkg_seed, newVal=lab_val)
with
cv2.floodFill(img_floodfill, mask_, seedPoint=(bkg_seed[1], bkg_seed[0]), newVal=lab_val)