bwconncomp returns a variable with 4 fields. one of them is pixelIdxlist. it contains the connected component list.how can we extract each component and show in different images.
4 次查看(过去 30 天)
显示 更早的评论
in my code pixelIdx has 4 components:
PixelIdxList: {[866x1 double] [628x1 double] [1092x1 double] [4x1 double]}
how can I store each component in a different image so that it can b processed further..
can anyone plz help me to write the code for this..
采纳的回答
Anand
2013-12-4
You can use the regionprops function with 'Image' as the requested statistic and pass the output of bwconncomp to it. Your code would look like this:
BW = imread('text.png');
CC = bwconncomp(BW);
stats = regionprops(CC,'Image');
%Display the first component as an image
imshow(stats(1).Image);
Note that you can instead directly call regionprops on the binary image BW. regionprops will internally invoke bwconncomp for you.
stats = regionprops(BW,'Image');
0 个评论
更多回答(1 个)
Image Analyst
2013-12-4
I know this is old, but if anyone wants to do this, each blob that was measured (4 in Gaur's case) will have a label if you called bwlabel() or bwconncomp() prior to calling regionprops(). To get each by itself, you use ismember():
[labeledImage, numberOfBlobs] = bwlabel(binaryImage);
measurements = regionprops(labeledImage);
for blob = 1 : numberOfBlobs
thisBlob = ismember(labeledImage, 1);
% Display blob in a new figure.
figure;
imshow(thisBlob);
% Or use imwrite if you want to save to disk.
eightBitImage = uint8(255*(thisBlob>0));
filename = sprintf('Blob #%d.png', blob);
imwrite(eightBitImage, filename);
end
You can also look at my Image Segmentation Tutorial to see how you can use the BoundingBox property if you want the blob cropped out to form a smaller image instead of the above, which has the full sized image.
1 个评论
Iman Haghgooie
2015-8-6
Hi Image Analyst, bwlabel is the most common way of labeling connected pixels. But it is memory-intensive and computationally expensive. bwconncomp provides much better performance for real-time applications. Pls see below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180224/image.png)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!