How to fill color correctly in closed curve using floodfill

I would like to fill black and white image using floodfill operation but some parts are missing as shown by first row images and some parts are not filled properly (looks some parts become separated from main object) as shown by second row images . To describe, I show some examples below :

below is my code :

im_in = cv2.imread(path to image,cv2.IMREAD_GRAYSCALE)
th, im_th = cv2.threshold(im_in, 220, 255, cv2.THRESH_BINARY_INV)
 im_floodfill = im_th.copy()
 h, w = im_th.shape[:2]
 mask = np.zeros((h+2, w+2), np.uint8)
 cv2.floodFill(im_floodfill, mask, (0,0), 255)

please advise

thank you

use fillPoly or fillConvexPoly instead

related:

Wow thanks a lot. I think it is solved now