I have some images and the corresponding ROI positions, I want to use these data to generate a mask image, I have tried to generate some mask images, but it works fine when there is only one ROI, but when there are more than two ROIs causes mask to connect.
Is there any way to generate a Mask image without knowing how many ROIs there are?
code:
import numpy as np
import cv2
from skimage import morphology
def get_mask(imgshape, roi):
mask = np.zeros(imgshape, dtype=np.int32)
mask = cv2.fillConvexPoly(mask, roi, 255)
mask = morphology.binary_closing(mask)
return mask
mask_img = get_mask((200,200), roi_pos)
ROI = [[104, 94],[105, 94],[106, 93],[105, 92],[104, 91],
[103, 92],[103, 93],[ 95, 94],[ 96, 94],[ 97, 92],[ 97, 91],
[ 97, 91],[ 95, 91],[ 94, 91],[ 93, 93],[ 94, 94]]


