How do i copy or erase a labeled object in an image?
1 view (last 30 days)
Show older comments
Hi there. I am working on a project that involves multiple objects in an image. I need to know how can I use each object separately to work with it. One way that i thought might work is to copy each labeled object into a new image (empty one). Can anyone tell me how to do this? Or another possible way would be to simply erase all other labeled objects, so that i only have the first one. Can someone please tell me how can I do this? Both methods are OK.
0 Comments
Answers (1)
Image Analyst
on 25 Mar 2015
You can use ismember() to extract the labeled objects that you want. If you want, say, blob #42, you can do this to get a labeled image with just blob 42
labeledImage2 = ismember(labeledImage, 42); % A labeled image.
If you want a binary image, just compare to 0:
labeledImage2 = ismember(labeledImage, 42) > 0; % A binary image.
You can also pass in an array:
labeledImage2 = ismember(labeledImage, [10, 13, 42]); % A labeled image.
There is also a function called bwselect() that you may be interested in. This lets you specify coordinates and will extract the blobs that contain those coordinates.
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!