How to copy a a ROI created by roipoly ?

7 次查看(过去 30 天)
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 ?

回答(1 个)

Subhadeep Koley
Subhadeep Koley 2019-11-3
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!

Translated by