删除圆度小于阈值的区域。

5 visualizaciones (últimos 30 días)
N/A
N/A el 19 de Nov. de 2022
%边界寻找
[B,L] = bwboundaries(bw,'noholes');
figure;imshow(L)
hold on
%计算面积
roundness = zeros(size(B,1), 3);
%圆度的统计值,将图形中每个分离的连通区域的周长、面积和圆度值记录下来
stats = regionprops(L,'Area','Centroid');
threshold = 0.87;
% 循环处理每个边界
for k = 1:length(B) % 获取边界坐标
boundary = B{k}; % 计算周长
delta_sq = diff(boundary).^2;
perimeter = sum(sqrt(sum(delta_sq,2))); % 对标记为K的对象获取面积
area = stats(k).Area; % 圆度计算公式4*PI*A/P^2
metric = 4*pi*area/perimeter^2; % 结果显示
roundness(k,:) = [perimeter, area, metric ];
%标记圆度大于threshold = 0.87 的对象
if metric >threshold
metric_string = sprintf('%2.2f',metric);
centroid = stats(k).Centroid; %centroid是目标k的质心
plot(centroid(1), centroid(2),'k.');
text(centroid(1), centroid(2),metric_string,'Color','r',...
'FontSize',14,'FontWeight','bold');
end
end
title('圆度识别结果,越圆越接近1');
上面的代码找到了指定圆度的区域,但是我该如何使用如下的命令删除那些圆度不够的区域呢?
% mask= ismember(L, find([stats.Area]>=500));
代码里的metric怎么和区域L建立关系呢?

Respuestas (0)

Categorías

Más información sobre Spline Postprocessing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!