Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在matlab中使用hough变换正确绘制直线_Matlab_Image Processing_Geometry_Hough Transform - Fatal编程技术网

无法在matlab中使用hough变换正确绘制直线

无法在matlab中使用hough变换正确绘制直线,matlab,image-processing,geometry,hough-transform,Matlab,Image Processing,Geometry,Hough Transform,我使用代码使用Houghtranform绘制线条。在此代码中,在Polar空间中绘制图像。我想在笛卡尔空间中绘制检测到的线。因此,在我的帮助下,我编写了如下代码: imBinary = flipud(edge(rgb2gray(im),'sobel')); [imWidth,imLenght]=size(imBinary); [interestPointY , interestPointX] = find(imBinary); numberOfInterestingPoints=numel(in

我使用代码使用
Hough
tranform绘制线条。在此代码中,在
Polar
空间中绘制图像。我想在
笛卡尔
空间中绘制检测到的线。因此,在我的帮助下,我编写了如下代码:

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]);
不幸的是,我没有像这样获得正确的线条和图像:

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]);

我的问题是,我不能正确地画线是什么错误?

我建议提供一个。没有人会读你的大量垃圾代码。@谢谢你把我的代码称为垃圾:)。这与链接中经常用于hough变换的代码相同!原谅我,我真的想写chunk。注意,实际上有一个