资源技术动态图像入门:MATLAB图像识别

图像入门:MATLAB图像识别

2019-10-08 | |  99 |   0

原标题:图像入门:MATLAB图像识别 

来源:CSDN博主   齐红建 ]       链接:https://blog.csdn.net/Qhj_Miracle/article/details/80958673


初学数字图像处理,做一个练习,识别图中的图形形状,颜色,位置,面积,周长

20180708132358899.png


基本思路:首先先对图像进行裁剪,增强等处理,使图片成为简单的二值图。

接着提取图像边缘


对图像处理后就可以进行寻找质心并标记、利用HOUGH变换检测直线、利用圆的周长和面积的关系判断是否为圆形,求图形的周长、面积、RGB等等操作

下面附全部代码,欢迎大家一起学习讨论~


f=imread('C:UsersQHJDesktopdemo.png');

f=f(:,:,3);

f=histeq(f,256);       %增强对比度

f=im2bw(f,0.386);

rowhigh=102+276-1;     %提取有用部分

colhigh=193+277-1;

f=f(102:rowhigh,193:colhigh);

se=strel('square',14); %开闭运算

fo=imopen(f,se);

f2=imclose(fo,se);

f2=~f2;

imshow(f2);

 

g=edge(f2,'sobel',0.47);

[B,L] = bwboundaries(f2,'noholes');

hold on

for k = 1:length(B)    % 标记边界

  boundary = B{k};

  plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 2)

end

 

hold on              

[L1,n]=bwlabel(g);     %标定质心

ff=imread('C:UsersQHJDesktopdemo.png');

for k=1:n

  [r,c]=find(L1==k);

  rbar=mean(r);

  cbar=mean(c);

  plot(cbar,rbar,'Marker','*','MarkerEdgeColor','blue');

  fprintf('行坐标为%9.2f    , ',cbar)

  fprintf('列坐标为%9.2fn',rbar);

rgb=ff(floor(cbar)+193,floor(rbar)+102,:)          %读取RGB值

 

end

 

axis on,axis normal;

[H,theta,rho]=hough(g);%判断直线

peak=houghpeaks(H,11);

lines=houghlines(g,theta,rho,peak,'FillGap',10,'MinLength',31);%

hold on

for k=1:length(lines)

  xy=[lines(k).point1;lines(k).point2];

  plot(xy(:,1),xy(:,2),'LineWidth',2.5,'Color','blue');

end

 

l=regionprops(L,'Perimeter','Area');  %求周长,面积

l.Perimeter   

l.Area

 

stats = regionprops(L,'Area','Centroid','Perimeter');

threshold = 0.95;

for k = 1:length(B)

  boundary = B{k};

  area = stats(k).Area;                

  %perimeter=stats(k).Perimeter;

  delta_sq = diff(boundary).^2;    

  perimeter = sum(sqrt(sum(delta_sq,2)));                 %利用4pi*面积/周长^2=1判断圆

  metric = 4*pi*area/perimeter^2;

  metric_string = sprintf('%2.2f',metric) ;

  text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'Color','g',...

       'FontSize',14,'FontWeight','bold');

  if metric > threshold

     centroid = stats(k).Centroid;

     text(centroid(1)-10,centroid(2)-10,'圆','Color','b','FontSize',10,'FontWeight','bold');

  end

 20180708183025107.png


THE END

免责声明:本文来自互联网新闻客户端自媒体,不代表本网的观点和立场。

合作及投稿邮箱:E-mail:editor@tusaishared.com

上一篇:人脸识别、3D表情,百度输入法玩转表情黑科技

下一篇:Matlab实现人脸识别

用户评价
全部评价

热门资源

  • 应用笔画宽度变换...

    应用背景:是盲人辅助系统,城市环境中的机器导航...

  • GAN之根据文本描述...

    一些比较好玩的任务也就应运而生,比如图像修复、...

  • 端到端语音识别时...

    从上世纪 50 年代诞生到 2012 年引入 DNN 后识别效...

  • 人体姿态估计的过...

    人体姿态估计是计算机视觉中一个很基础的问题。从...

  • 谷歌发布TyDi QA语...

    为了鼓励对多语言问答技术的研究,谷歌发布了 TyDi...