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!



