zoukankan      html  css  js  c++  java
  • MatLab计算图像圆度

    本文所述方法可以检测同一图像中的多个圆形(准确的说,应该是闭合图像)。

    在Matlab2010a中可以实现。

    附录效果图:

     

    %颗粒圆度 clear;close all; %% %读取源图像 I = imread('999.png'); figure;imshow(I); %% %灰度化、取反 h = rgb2gray(I); figure;imshow(h);%灰度图像 h = imcomplement(h);%取反 figure;imshow(h); %% %中值滤波、二值化 h = medfilt2(h,[4,4]); bw = im2bw(h,graythresh(h)); %% %消除噪点 se = strel('disk',2); bw = imclose(bw,se); figure;imshow(bw); %% %填补闭合图形,填充色为白色 bw  = imfill(bw,'holes'); %% %边界寻找 [B,L] = bwboundaries(bw,'noholes'); % 为每个闭合图形设置颜色显示 figure;imshow(label2rgb(L, @jet, [.5 .5 .5])) hold on for k = 1:length(B)   boundary = B{k};   plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2) end %% %计算面积 stats = regionprops(L,'Area','Centroid');

    threshold = 0.94;

    % 循环处理每个边界,length(B)是闭合图形的个数,即检测到的陶粒对象个数 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;

      % 结果显示   metric_string = sprintf('%2.2f',metric);

      % 用一个黑色小圆圈标记圆度大于threshold = 0.94 的对象   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(['圆度识别结果,越圆越接近1,']);


     

  • 相关阅读:
    Promise笔记
    srping-cloud-stream集成rocketmq
    mysql锁
    profiling分析
    mysql慢查询
    sql语句中in与exists的使用区别
    数据库死锁的解决办法
    死锁的形成以及处理
    百万数据修改索引,百万数据修改主键
    创建视图索引
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3357837.html
Copyright © 2011-2022 走看看