要求:拍摄树叶照片,正反两张,提取叶脉,测量叶脉的分支,以及分支的倾斜角。
霍夫变换以及canny算子理论百度。。。。
程序:
clc,close
BW=imread('leaf.jpg');
BW=rgb2gray(BW);
thresh=[0.13,0.3]; %阈值设置根据图像自定义范围
sigma=1;%定义高斯参数,1-3
f = edge(double(BW),'canny',thresh,sigma);
figure(1),imshow(f,[]);
title('canny 边缘检测');%canny边缘算子
[H, theta, rho]= hough(f,'RhoResolution', 0.5,'ThetaResolution',0.75);
%imshow(theta,rho,H,[],'notruesize'),axis on,axis normal%霍夫变换空间图
%xlabel('\theta'),ylabel('rho');
peak=houghpeaks(H,8,'threshold', ceil(0.3*max(H(:)))); %求出显示霍夫变换矩阵中的8个极值点
hold on
lines=houghlines(f,theta,rho,peak);% 找原图中的线
figure,imshow(f,[]),title('Hough Transform Detect Result'),hold on
max_len=0;
for k=1:length(lines)
xy=[lines(k).point1;lines(k).point2];
xielv(k)=(lines(k).point2(1)-lines(k).point1(1))/(lines(k).point2(2)-lines(k).point1(2)+0.0001);%求直线斜率
plot(xy(:,1),xy(:,2),'LineWidth',4,'Color',[.6 .6 .6]); %绘制各条直线
end
ang = atan(xielv)*180/pi%求各条直线角度
原始图像:
canny算子边缘检测结果
霍夫变换取直线结果:
霍夫变换直线结果还是不明显,对图片识别度不高。

该博客介绍了如何使用MATLAB进行树叶叶脉的提取,通过应用Canny算子进行边缘检测,然后利用霍夫变换测量叶脉的分支及其倾斜角度。然而,霍夫变换在实际操作中对图片的识别效果并不理想。
1527

被折叠的 条评论
为什么被折叠?



