save only specefic connected components

Hi, From a gray image , I extract all the connected components using bwconcomp, Then I work on each connected component. I want to draw in a new image with the size of the originam image some specefic connected components. I saw many works based on the area , the biggest component ... but for me I have new parameter that will filter the cinnected components, How can I draw in a new image with the original image size a specific connected component in its original place?? Thank you :)

回答 (1 件)

Image Analyst
Image Analyst 2017 年 3 月 1 日
編集済み: Image Analyst 2017 年 3 月 1 日

1 投票

You can extract any component from your labeled image into a new binary image using ismember:
binaryImage = ismember(labeledImage, index);
This will get only one blob - the one that was labeled with a number of "index".
If you want to mask the image with that blob and get a gray scale image then do this:
maskedImage = grayImage; % Initialize
maskedImage(~binaryImage) = 0; % Do the masking.

7 件のコメント

Flore Massoulié
Flore Massoulié 2017 年 3 月 1 日
編集済み: Flore Massoulié 2017 年 3 月 1 日
thank you for your reply, sorry but I will add many components in the same image, how can I save their indexes ? I didn't get the idea :(
Flore Massoulié
Flore Massoulié 2017 年 3 月 1 日
for example like this,
Image Analyst
Image Analyst 2017 年 3 月 1 日
index can be an array of indexes if you want to extract several components.
Flore Massoulié
Flore Massoulié 2017 年 3 月 1 日
Sorry but this is not working for me, my original image is Img and the component I want to draw exp F(i).Image, then when I do binaryImage = ismember(Img, F(i).Image); is that what you mean ? but I got a white image nothing in it
Image Analyst
Image Analyst 2017 年 3 月 1 日
Is "F(i).Image" a scalar integer that contains the ID label of the blob you want to extract? If so, then yes, that should work.
Flore Massoulié
Flore Massoulié 2017 年 3 月 2 日
Hi again, No F(i).Image is the image of the connected component;
Image Analyst
Image Analyst 2017 年 3 月 2 日
Since you already have the image of the connected component, you can just use it as a mask on the original image:
If you want to mask the image with that blob and get a gray scale image then do this:
maskedImage = grayImage; % Initialize
mask = F(i).Image > 0; % Convert "the image of the connected component" into a logical mask.
maskedImage(~mask) = 0; % Do the masking.

サインインしてコメントする。

質問済み:

2017 年 3 月 1 日

コメント済み:

2017 年 3 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by