Hi Cristhian,
The “createMask” function requires the current figure in MATLAB to contain the image on which the ROI is drawn. In the provided code, the error occurs because the function is being called within a loop where multiple ROIs are drawn. However, the image associated with each ROI is not present in the current figure, leading to the error.
To resolve this issue, we need to ensure that the image is displayed in the current figure before creating the masks. This can be achieved by creating a new figure for each image as shown in the following code snippet:
figure; % Create a new figure for each image
imshow(img, []);
hold on;
for ind = 1:numel(blocations)
pos = blocations{ind};
pos = fliplr(pos);
mask = drawfreehand('Position', pos);
BW = createMask(mask);
morph = imopen(BW, se);
end
hold off;
Please refer to this for more information: