My question:
How can I save the 'for' command values of objects that have an area greater than 50? I need to save the numbers of these objects because later I will calculate the distance between two of them, would anyone know how to store those values?
Code:
original = imread('A.jpg');
verde = original(:,:,2) > 250;
imshow(verde);
[B,L] = bwboundaries(verde, 'noholes');
stats = regionprops(L, 'Area');
qtd_verde = sum([stats.Area] > 50);
imshow(original);
hold on
for k = 1:length(B)
area = stats(k).Area;
if area > 50
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'black', 'LineWidth', 2);
text(boundary(1,2), boundary(1,1), sprintf('%.0f',k),...
'Color', 'white',...
'FontSize', 12,...
'FontWeight', 'bold',...
'BackgroundColor', 'black');
end
end
hold off
@EDIT
I was able to solve by selecting the geometric form that interested me, in this case a rectangle, soon it will only appear the two objects 'always'. But if anyone knows how to solve the previous problem, it would be very interesting and would help me a lot!
original = imread('A.jpg');
verde = original(:,:,2) > 218;
imshow(verde);
[B,L] = bwboundaries(verde, 'noholes');
MN = [3 15];
SE = strel('rectangle', MN);
Iopenned = imopen(L,SE);
imshow(Iopenned);
%=============
[J,H] = bwboundaries(Iopenned, 'noholes');
stats = regionprops(Iopenned, 'Area');
qtd_verde = sum([stats.Area] > 50)
imshow(original);
title(sprintf('\fontsize{16}{Existem %d objetos verdes nessa imagem}', qtd_verde));
hold on
for k = 1:length(J)
boundary = J{k};
plot(boundary(:,2), boundary(:,1), 'black', 'LineWidth', 2);
text(boundary(1,2), boundary(1,1), sprintf('%.0f',k),...
'Color', 'white',...
'FontSize', 12,...
'FontWeight', 'bold',...
'BackgroundColor', 'black');
end
hold off