how to mask a region under the boundary?

I have an RGB image in which I have segmented certain portions of the image using bwboundaries commands in matlab. Now i want the region under the boundary to be masked with green color. For this i want develop algorithm dynamically
& not by using imfreehand command. could any one help on this? . I have attached the rgb image with boundaries marked...

 Akzeptierte Antwort

Image Analyst
Image Analyst am 18 Aug. 2014

0 Stimmen

Have a loop. For each boundary that you have, call poly2mask. Then "OR" it in to a binary image that you will be building up. Then cast your image to color if necessary, then set masked areas to green. I'll give you pseudocode. See if you can figure it out.
binaryImage = false(rows, columns);
for k = 1 : length(boundaries)
thisBoundary = boundaries{k};
x = thisBoundary(:,1);
y = thisBoundary(:, 2);
thisMask = poly2mask(x, y, rows, columns);
binaryImage = binaryImage | thisMask;
end
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
redChannel(binaryImage) = 0;
greenChannel(binaryImage) = 255;
blueChannel(binaryImage) = 0;
% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
imshow(rgbImage);

4 Kommentare

Anand
Anand am 18 Aug. 2014
Bearbeitet: Image Analyst am 18 Aug. 2014
The above code is masking almost of my entire image... I have attached output i got after performing above code on my image. plz any modifications.
Image Analyst
Image Analyst am 18 Aug. 2014
Bearbeitet: Image Analyst am 18 Aug. 2014
You must have boundaries that enclose all of that. I don't have the code you used to binarize your image, nor do I have the code you used to find the boundaries of the blobs in the binary image. So I can't really help much anymore until you give me that, along with your original, non-annotated image (image with no green graphics on it).
Attach your images and code with the paper clip icon.
Image Analyst
Image Analyst am 18 Aug. 2014
Anand's Answer, and comment to that answer (which was the same) both moved here:
please provide your email id so that i will send my full code with images. Thank you for your help...
Image Analyst
Image Analyst am 18 Aug. 2014
Attach your images and code with the paper clip icon. I don't do free, private consulting via emails. The ability to share images and code is built into this Answers site.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by