3
My doubt:
How can I save the values of the 'for' command for objects that have an area greater than 50? I need to store the numbers of these objects because later I will calculate the distance between two of them, someone would know how to store these 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 managed to solve by selecting the geometric shape that interested me, in this case a rectangle, soon will appear only the two objects 'always'. But in case anyone knows how to solve the previous problem, it would be quite 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
Edited, but in case someone knows how to solve the initial problem, comments here!
– Bruno Falcon