Display each object in a binary image separately
5 ビュー (過去 30 日間)
古いコメントを表示
Hello everybody,
I have an image, with undefined number of objects, just like the image below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162063/image.png)
I want to create an image for each one of the objects. For this case, I want to create 4 images each one with only one object. The new images should have the same size as the original image.
Is there anyone who could help me?
Cheers,
Joaquim
3 件のコメント
Rik
2017 年 3 月 23 日
As long as it gets the job done it usually doesn't matter how efficient your code is in terms of memory (in most of my cases anyway).
採用された回答
Image Analyst
2017 年 3 月 23 日
See my Image Segmentation Tutorial: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862&sort=downloads_desc
Or, simply use ismember() to extract the blob you want. For example
[L, num] = bwlabel(BW);
for k = 1 : num
thisBlob = ismember(L, k);
figure
imshow(thisBlob, []);
end
13 件のコメント
Image Analyst
2021 年 9 月 5 日
My code puts it in a loop over all blobs and shows you each blob one at a time because k varies in the loop. Your code only shows you one blob -- the k'th blob. But you need to specify k. Which one of the 4 do you want? See the attached demo to understand how the blobs are numbered/labeled.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/730164/image.png)
MashalS
2021 年 9 月 6 日
CODE :
L= bwlabel(BW);
thisBlob= ismember(L,1);
figure
imshow(thisBlob, []);
@Image Analyst,I understand how are blobs labelled. In the above code , I have displayed blob 1 on the figure. Using the similar syntax , Is it possible to use "ismember" to display more than one blob? for example: I have an image with 9 objects in it and i want to display only blob no.1 ,6 and 7 to be displayed in one figure.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!