stats = regionprops(L,'Area','Centroid');
threshold = 0.94;
% 对每个周长操作
for k = 1:length(B)
boundary = B{k};
delta_sq = diff(boundary).^2; % 简单计算对象周长
perimeter = sum(sqrt(sum(delta_sq,2)));
area = stats(k).Area; % 求解面积
metric = 4*pi*area/perimeter^2; % 计算为圆形的概率
metric_string = sprintf('%2.2f',metric); % 显示结果
% 将大于阈值的对象标记上黑色的圆圈
if metric > threshold
centroid = stats(k).Centroid;
plot(centroid(1),centroid(2),'ko');
end
text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'Color','y','FontSize',14,'FontWeight','bold');
end
title(['Metrics closer to 1 indicate that ','the object is approximately round']);