MATLAB Answers

How can I draw on two ROI to create a mask on the same image?

23 views (last 30 days)
Anon
Anon on 9 Feb 2020
Answered: Subhadeep Koley on 10 Feb 2020
roi = images.roi.AssistedFreehand
draw(roi)
roi2 = images.roi.AssistedFreehand
draw(roi2)
mask = createMask(roi);
mask2 = createMask(roi2);
imshow(mask);
imshow(mask2);
%imshow(BW)
J=regionfill(I,mask)
H=regionfill(I,mask2)
figure
hold on
imshow(J)
imshow(H)
hold off
I want to draw two separate regions of interest within the same image to create a mask. Then use this mask with the regionfill function. However, I am able to draw two separate ROI with this script but it does not let me combine the two together as only one region is currently being filled.

  0 Comments

Sign in to comment.

Answers (1)

Subhadeep Koley
Subhadeep Koley on 10 Feb 2020
You can easily combine those two masks using the imadd() function. Refer the code below
close all ; clc;
I = imread('cameraman.tif');
figure; imshow(I, []);
roi = images.roi.AssistedFreehand;
draw(roi);
roi2 = images.roi.AssistedFreehand;
draw(roi2);
mask = createMask(roi);
mask2 = createMask(roi2);
% Combine 2 masks
combinedMask = imbinarize(imadd(mask, mask2));
% Apply the filter
J = regionfill(I, combinedMask);
% Display results
figure;
subplot(2, 2, 1); imshow(mask); title('Mask 1');
subplot(2, 2, 2); imshow(mask2); title('Mask 2');
subplot(2, 2, 3); imshow(combinedMask); title('Combined Mask');
subplot(2, 2, 4); imshow(J, []); title('Region filled image');
combinedMask.png
Hope this helps!

  0 Comments

Sign in to comment.

Sign in to answer this question.