Why find_contours can not give a exact outline?

I use skimage.measure.find_contours with a binary image. But nomatter how I adjust the parameter, level, high, low… and astype(int) or round the result, I can not get a exact outline.
I want to get a result like cv2.findContours.

Hi again Yan! This certainly looks like a bug. Would you mind providing a sample image and code to reproduce that figure? Thanks!


from skimage.io import imread

arr = (imread('test.png')==1).astype(np.uint8)
plt.plot(*find_contours(arr, 0.5)[0].T)

but if I use draw.circle or polygon to make a mask, the find_contours give a right result.

@yxdragon I wanted to explore this a bit more interactively so I put it in napari, and there the contours were perfect! It turns out that this is an xy/rc coordinates issue! If you change it to plt.plot(*find_contours(arr, 0.5)[0][:, ::-1].T), it lines up! It looks only a little bit off because the image is almost symmetric by transposition, but not quite.

Maybe it’s time to change your name to rcdragon? =P

1 Like

O!!!, I forgot it, Infact I translate the code from opencv, and the test image is almost diagonal-symmetry, So I fall into the adjusting parameter…