我使用this 代码使用Hough
转换来绘制线条。在此代码中,在Polar
空间中绘制了图像。我想在Cartesian
空间中绘制检测到的线条。因此,在this explanation的帮助下,我编写了这样的代码:
imBinary = flipud(edge(rgb2gray(im),'sobel'));
[imWidth,imLenght]=size(imBinary);
[interestPointY , interestPointX] = find(imBinary);
numberOfInterestingPoints=numel(interestPointX);
maxRadius=sqrt(imWidth^2 + imLenght^2);
polarRadius=(-maxRadius:1:maxRadius);
polarTheta=(-pi/2:(1/200):pi/2);
numberOfPolarThetas=numel(polarTheta);
houghMatrix=zeros(numel(polarRadius),numberOfPolarThetas);
polarAccumulator = zeros(numberOfInterestingPoints,numberOfPolarThetas);
cosine = (0:imWidth-1)'*cos(polarTheta);
sine = (0:imLenght-1)'*sin(polarTheta);
polarAccumulator((1:numberOfInterestingPoints),:) =cosine(interestPointY,:) + sine(interestPointX,:);
for i = (1:numberOfPolarThetas)
houghMatrix(:,i) = hist(polarAccumulator(:,i),polarRadius);
end
radiusDetect=[];angleDetect=[];
houghBinaryMax = imregionalmax(houghMatrix);
[Potential_radius ,Potential_angle] = find(houghBinaryMax == 1);
%[radiusIndex angleIndex] = find(houghMatrix > 0);
houghTmp= houghMatrix - lineThreshold;
for cnt = 1:numel(Potential_radius)
if houghTmp(Potential_radius(cnt),Potential_angle(cnt)) >= 0
radiusDetect = [radiusDetect;Potential_radius(cnt)];
angleDetect = [angleDetect;Potential_angle(cnt)];
end
end
radius=polarRadius(radiusDetect);
deg=polarTheta(angleDetect);
%find two points in cartesian space
x=radius.*cos(deg);
y=radius.*sin(deg);
x1=x+5.*cos(deg);
y1=y+5.*cos(deg);
imshow(imBinary);
hold on;
plot([x x1],[y y1]);
不幸的是我没有得到正确的行和我的图像:the blue lines are detected
我的问题是我无法正确绘制线条的错误是什么?