Hello Mat

 找回密码
 立即注册
查看: 5516|回复: 0

图像圆度计算

[复制链接]

1323

主题

1551

帖子

0

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22647
发表于 2018-4-22 10:55:44 | 显示全部楼层 |阅读模式
https://ww2.mathworks.cn/help/im ... -round-objects.html
metric = 4*pi*area/perimeter^2.
  1. [B,L] = bwboundaries(bw,'noholes');

  2. % Display the label matrix and draw each boundary
  3. imshow(label2rgb(L, @jet, [.5 .5 .5]))
  4. hold on
  5. for k = 1:length(B)
  6.   boundary = B{k};
  7.   plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
  8. end

  9. stats = regionprops(L,'Area','Centroid');

  10. threshold = 0.94;

  11. % loop over the boundaries
  12. for k = 1:length(B)

  13.   % obtain (X,Y) boundary coordinates corresponding to label 'k'
  14.   boundary = B{k};

  15.   % compute a simple estimate of the object's perimeter
  16.   delta_sq = diff(boundary).^2;   
  17.   perimeter = sum(sqrt(sum(delta_sq,2)));
  18.   
  19.   % obtain the area calculation corresponding to label 'k'
  20.   area = stats(k).Area;
  21.   
  22.   % compute the roundness metric
  23.   metric = 4*pi*area/perimeter^2;
  24.   
  25.   % display the results
  26.   metric_string = sprintf('%2.2f',metric);

  27.   % mark objects above the threshold with a black circle
  28.   if metric > threshold
  29.     centroid = stats(k).Centroid;
  30.     plot(centroid(1),centroid(2),'ko');
  31.   end
  32.   
  33.   text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'Color','y',...
  34.        'FontSize',14,'FontWeight','bold');
  35.   
  36. end

  37. title(['Metrics closer to 1 indicate that ',...
  38.        'the object is approximately round']);
复制代码






算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-11-25 13:52 , Processed in 0.202880 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表