MATLAB: Problem with multiplying labeled images in for loop.

for loopimage processingImage Processing Toolboxmultiplying images

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)

Best 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);