How to copy a a ROI created by roipoly ?

5 views (last 30 days)
Ahmad Alenezi
Ahmad Alenezi on 22 Oct 2019
Answered: Subhadeep Koley on 3 Nov 2019
Hi there
i created a ROI over a specific part of an image using roipoly (see image). i would like to copy this exact ROI shape (the blue mask only) to place it on another part of the same image. how can i copy the same ROI ?

Answers (1)

Subhadeep Koley
Subhadeep Koley on 3 Nov 2019
Ahmad, You can create the mask by double-clicking, or by right-clicking inside the region and selecting Create mask from the context menu. Once the generated binary mask is saved in your MATLAB workspace, you can apply that mask to to extract ROI from any image. Refer the code below.
[row, col] = size(originalImage);
maskedImage = zeros(size(originalImage)); % originalImage is the image you want to apply the mask on
for j = 1:row
for k = 1:col
if(yourBinaryMask(j,k) == 1) % yourBinaryMask is the mask you generated previously with roipoly
maskedImage(j,k) = originalImage(j,k); % maskedImage is the ROI masked image
end
end
end
Hope this helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!