Filling object contours

44 views Asked by At

I have a binary image with contours which was generated without any pre-built function using this. And the image is

enter image description here

Now, I would like to fill these objects based on the contours and the output is

enter image description here

Now, I have the second image for which I extracted the contours using cv2.Laplacian as below

enter image description here

And the object filling looks as below

enter image description here

And the code used for filling the contours is

import numpy as np
import cv2 as cv

image = cv.imread('test1.png')
im_floodfill = image.copy()
h, w = image.shape[:2]
mask = np.zeros(( h +2, w+ 2), np.uint8)
cv.floodFill(im_floodfill, mask, (0, 0), (255, 255, 255))

cv.imshow('Full Mask', im_floodfill)
cv.waitKey(0)

cv.imwrite('filled_circle_200_big.png', im_floodfill)

Now, I don't understand why do I get two different fills with the same piece of code? In the first image it fills correctly but in the second, it just fills the top part of the image which is background,but doesn't go beyond that. Is it because of the way the contours are extracted or Am I missing something here?

Thanks in advance

0

There are 0 answers