0

i have image that contain many blobs . my problem is that how to test each blob individually by masking it up on the original image?! i tried this code but i did not know how to complete it

labelledImage = bwconncomp(segmentedimage);             
stats = regionprops(labelledImage, 'all');
centroids = cat(1, stats.Centroid);
[row ,col] = size(centroids);
for i = 1 : row 
    areaMatr(i) = stats(i).Area; % gives area for each blob in your image

   % what i have to put here for testing the blob and masking it out over the 
   % original image? any help?
end

2 Answers 2

1

It may be more prudent to use bwlabel instead, which assigns a unique ID to each unique blob in your image. The first output gives you this labelling and the second output gives you the total number of unique IDs / blobs in the image. Bear in mind that this image needs to be binary, but given your choice of variable name, I'm assuming this to be true.

Once you find all unique IDs, you can loop through each unique ID, mask out the blob and apply regionprops to this blob.

Something like this:

%// Apply bwlabel to the image
[labelledImage, numLabels] = bwlabel(segmentedimage); 

%// For each label...
for idx = 1 : numLabels

    %// Create a mask for this particular blob
    mask = labelledImage == idx;

    %// Apply regionprops on this mask only
    stats = regionprops(mask, 'all');

    %// Use stats and mask in however way you see fit
    %// ...
    %// ...
end
Sign up to request clarification or add additional context in comments.

13 Comments

hi rayryeng. exactly i am thinking to do that but how ?! i want to get the bounding box for each blob separately and then masking it onto the original image, then computing the number of pixels within each bounding box of masking original image then decide who the desired blob and who will be discard. kindly help as soon as posible
@saif - That wasn't part of your original question. I'm gonna leave that unanswered and let you figure that out as you haven't tried anything.
please do not be angry with me.
CC = bwconncomp(fod); % find connected blobs and detecting its number
pixelcount=1:CC.NumObjects; % creating a vector for saving the largest pixels number found in each blob then use it for comparing with other blobs and the large number win
|
0

'stats.BoundingBox' will give you the coordinates of each blob. You can use the coordinates to mask the blob onto the original image.

1 Comment

you are right but i want the code to bounding each blob by box separately and then masking it onto the original image(to get only the pixels that fall within the bounding box) then computing the number of pixels within each bounding box separately finally decide who the desired blob and who will be discard. kindly answer my as soon as possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.