Problem with multiplying labeled images in for loop.

Hello, I have problem with displying one image of several objects that was earlier labeled. Here's a code:
close all
clear all
Orginal_img=imread('Orginal_img.png');
Label_img = bwlabel((Orginal_img),8);
disp(' ')
disp(['Number of objects in picture: ' int2str(max(max(Label_img)))]);
%it's 27 objects
disp(' ')
figure
imshow(Label_img);
title('Obraz ety');
i=1;
a=1:i:27;
for object_nr=a
Object_img = Label_img == object_nr;
FD=imFeretDiameter(Object_img);
disp(['Feret Diameter: ' num2str(FD)]);
if FD>120
All_objects_img=immultiply(imcomplement(Object_img),imcomplement(Object_img+1));
figure
imshow(All_objects_img,'InitialMagnification','fit')
title('All objects imgage')
else
end
end
After labeling I callculated Feret Diameter to remove objects that are not thick and long enough. My problem is that i want to display now all other objects (that were not removed) in one image. I know that I have to multiply all pictures that are consistent with condition (FD>120) but it doesn't work. Please help and thank you in advance. Here's a picture (Orginal_img)

 Accepted Answer

We don't know what imFeretDiameter() does. But basically you need a list of the label ID's of "keeper" blobs and "reject" blobs. Then you can use ismember() on the labeled image to extract only the keeper blobs
keeperBlobs = ismember(labeledImage, keeperIndexes);

4 Comments

Thanks for your answer. I downloaded this file https://www.mathworks.com/matlabcentral/fileexchange/30402-feret-diameter-and-oriented-box to be able to calculate imFeretDiameter. As far as I know imFeretDiameter() tells about elongation of object. I downloaded your Image Segmentation Tutorial and I have a question. Is there any way to use imFeretDiameter paramiter in regionprops or I have to use default paramiters as Area, BoundingBox, Centroid e.t.c.?
Regionprops does not return feret diameters, nor can you "use imFeretDiameter paramiter in regionprops". You can't "use" any custom variable in regionprops() or bwpropfilt().
Related measurements that regionprops does provide is MajorAxisLength and MinorAxisLength, though they're the axis lengths of an ellipse fitted to your blob. However, that may come in useful if you need to find the aspect ratio of your blob to see if it's long and skinny or more rounded/square/compact.
Ok I will try to use them. Thank you for help.
You're welcome. Thanks for Accepting the answer. You also might like to run my Image Segmentation Tutorial or other demos in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!