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 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
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..
1 commentaire
Réponse acceptée
  Anand
    
 le 4 Déc 2013
        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 commentaires
Plus de réponses (1)
  Image Analyst
      
      
 le 4 Déc 2013
        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 commentaire
  Iman Haghgooie
 le 6 Août 2015
				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.

Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



