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.

조회 수: 2 (최근 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
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');

추가 답변 (1개)

Image Analyst
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
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.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by