Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.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

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 检测直线的端点_Matlab_Image Processing - Fatal编程技术网

Matlab 检测直线的端点

Matlab 检测直线的端点,matlab,image-processing,Matlab,Image Processing,我想检测下图所示的点: 到目前为止,我已经做到了: [X,map] = rgb2ind(img,0.0); img = ind2gray(X,map); % Convert indexed to grayscale level = graythresh(img); % Compute an appropriate threshold img_bw = im2bw(img,level);% Convert grayscale to binary mask = zeros(size(im

我想检测下图所示的点:

到目前为止,我已经做到了:

[X,map] = rgb2ind(img,0.0);
img = ind2gray(X,map);    % Convert indexed to grayscale
level = graythresh(img);   % Compute an appropriate threshold
img_bw = im2bw(img,level);% Convert grayscale to binary
mask = zeros(size(img_bw));
mask(2:end-2,2:end-2) = 1;
img_bw(mask<1) = 1;
%invert image
img_inv =1-img_bw;
% find blobs
img_blobs = bwmorph(img_inv,'majority',10);
% figure, imshow(img_blobs);
[rows, columns] = size(img_blobs);
for col = 1 : columns
    thisColumn = img_blobs(:, col);
    topRow = find(thisColumn, 1, 'first');
    bottomRow = find(thisColumn, 1, 'last');
    img_blobs(topRow : bottomRow, col) = true;
end
inverted = imcomplement(img_blobs);
ed = edge(inverted,'canny');
figure, imshow(ed),title('inverted');
[X,map]=rgb2ind(img,0.0);
img=ind2gray(X,map);%将索引转换为灰度
级别=灰度阈值(img);%计算适当的阈值
img_bw=im2bw(img,级别);%将灰度转换为二进制
掩码=零(大小(img_bw));
掩模(2:end-2,2:end-2)=1;

img_bw(mask顶点显然是坐标最高的白色像素,很容易获得

底线不是很明确,你能做的就是

  • 沿着顶点边缘,直到在左侧和右侧达到局部最小值。这将为您提供一条线段,您可以通过顶点与垂直线相交

  • 如果您知道峰值宽度,请尝试垂直方向上通过顶部点向下的每个像素,然后停止,直到它在与峰值的距离相等的位置没有左邻域或右邻域

  • 如上所述,但当左右邻域之间的距离超过阈值时停止


  • 在这种特殊情况下,可以考虑在Matlab中使用<代码> HythLeangs<代码>。设置所需的<代码>θ< /代码>和<代码> min长参数值,你应该能够得到两条与你的峰值平行的垂直线。你可以使用垂直线的端点,得到底部的点。

    下面是一个示例代码

    [H,theta,rho] = hough(bw,'Theta',5:1:30);%This is the angle range
    P = houghpeaks(H,500,'NHoodSize',[11 11]);
    lines = houghlines(bw,theta,rho,P,'FillGap',10,'MinLength',300);
    

    是一个完整的描述,说明了houghlines实际上是如何工作的。

    是的,我可以找到顶点。你告诉我的想法也在我脑海中出现,找到两条线的交点作为底点。这对我来说似乎很难编码。在这种情况下,即使我不想找到确切的中点,但要找到离它最近的任何点,不管是左还是右。那么可能的方法是什么?“这对我来说似乎很难”:算了吧,不是!@user8126672如果你不定义这个点是什么,你就找不到那个点。如果没有一个清晰的定义来开发一个健壮的算法,你最终只会得到一些适用于这个图像的糟糕代码,其他什么都没有。否则你可以用鼠标来选择那个点。。。