问题描述:

After finding boundaries of my regions of interest in an RGB image I want to fill them with specific color on the original picture

img=imread('I.png');

BW=~im2bw(img,0.5);

B = bwboundaries(a2);

for k = 1:length(B)

boundary = B{k};

% here should color everything inside boundary in blue

end

What function can I use to do this? I tried also using imshow() and than ploting regions on it, but don't know how to save it in the original resolution.

网友答案:

If you insist on filling with polygon, you can use fill, but then you might face some problems:

img = imread('Prueba.jpg');
figure;
imshow(img)

BW = ~im2bw(img, 0.55);
B = bwboundaries(BW);
hold on
for k = 1:length(B)
   boundary = B{k};
   fill(boundary(:, 2), boundary(:, 1), 'b')
end

As shown in this example, there are regions of the image that are surrounded by a boundary but they are actually supposed to be outside the boundary.

Instead, in this way you can avoid the issue:

imgR = img(:, :, 1);
imgG = img(:, :, 2);
imgB = img(:, :, 3);
imgR(BW) = 0;
imgG(BW) = 0;
imgB(BW) = intmax(class(imgB));
IMG = cat(3, imgR, imgG, imgB);
figure; imshow(IMG)

相关阅读:
Top