Matlab 从提取的叶脉计算角度
我试图在matlab中计算叶脉之间存在的角度。我的想法是使用Hough检测线(静脉),然后计算角度。但是当我尝试检测线条时得到的结果有点奇怪 代码如下:Matlab 从提取的叶脉计算角度,matlab,image-processing,Matlab,Image Processing,我试图在matlab中计算叶脉之间存在的角度。我的想法是使用Hough检测线(静脉),然后计算角度。但是当我尝试检测线条时得到的结果有点奇怪 代码如下: [H,theta,rho] = hough(vein); P = houghpeaks(H,4); x = theta(P(:,2)); y = rho(P(:,1)); %lines = houghlines(BW,theta,rho,P,'FillGap',2,'MinLength',4); lines = houghlines(BW,th
[H,theta,rho] = hough(vein);
P = houghpeaks(H,4);
x = theta(P(:,2));
y = rho(P(:,1));
%lines = houghlines(BW,theta,rho,P,'FillGap',2,'MinLength',4);
lines = houghlines(BW,theta,rho,P);
figure, imshow(vein), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
% highlight the longest line segment
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','red');
有什么想法吗?我想你只是把矩阵的名字混在一起了 在您的代码中,有
静脉
矩阵和BW
矩阵。您正在使用:
- 静脉此处:
[H,θ,rho]=hough(静脉)代码>
- BW此处:
line=houghlines(BW,theta,rho,P)代码>
BW=静脉代码>,结果就不那么奇怪了:
vein = imbinarize(rgb2gray(imread('https://i.stack.imgur.com/cuwb0.jpg'))); %Read image, and convert to binary
BW = vein; %Copy vein to BW
[H,theta,rho] = hough(vein);
P = houghpeaks(H,4);
x = theta(P(:,2));
y = rho(P(:,1));
%lines = houghlines(BW,theta,rho,P,'FillGap',2,'MinLength',4);
lines = houghlines(BW,theta,rho,P);
figure, imshow(vein), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
% highlight the longest line segment
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','red');
结果:
什么是“奇怪”?Hough变换对曲线没有用处。