MatLab:二值图像的角点检测

use*_*340 5 matlab rounded-corners computational-geometry matlab-cvst corner-detection

我正在尝试找到一种方法来在 MatLab 中找到该二值图像上的角点

二值图像

我一直在尝试找到一种方法来在该图像上拟合三角形并找到顶点。我尝试过寻找角点,但它返回的值并不总是正确的。
有什么方法可以锐化边缘,以便角函数可以返回更好的结果吗?

我很感激任何意见!谢谢!

在此输入图像描述

什么策略看起来更简单、更有效?我可以使用哪些现有的 MatLab 函数?

Sha*_*hai 3

让我们尝试一种更代数的方法,而不是图像处理方法。

您有白色像素 - 平面上的 2D 点,并且您希望找到三个半平面(直线)来最好地将这些点与平面的其余部分分开。

那么,让我们开始吧

img=imread('https://i.stack.imgur.com/DL2Cq.png'); %// read the image
bw = img(:,:,1) > 128;  %// convert to binary mask
[y x] = find(bw);  %// get the x-y coordinates of white pixels
n=numel(x);  %// how many do we have
Run Code Online (Sandbox Code Playgroud)

为了稳定性,我们减去所有点的平均值 - 将白色像素以原点为中心:

mm = mean([x y],1); 
mA = bsxfun(@minus, [x y], mm);
Run Code Online (Sandbox Code Playgroud)

(x, y)现在,一条线可以用两个参数来描述,即所有满足 的点L(1)*x + L(2)*y = 1。为了找到一条所有点都严格位于其一侧的线,这个不等式必须对于(x,y)集合中的所有点都成立:L(1)*x + L(2)*y <= 1L我们可以强制这些不等式并使用以下方法搜索满足此约束的最紧半平面quadprog

L1 = quadprog(eye(2), -ones(2,1), mA, ones(n,1));
L2 = quadprog(eye(2), ones(2,1), mA, ones(n,1));
L3 = quadprog(eye(2), [1; -1], mA, ones(n,1));  
Run Code Online (Sandbox Code Playgroud)

请注意如何通过更改二次优化目标f,我们能够获得分隔白色像素的不同半平面。

一旦我们有了这三条线,我们就可以得到交点(将它们从原点移回mm):

x12=inv([L1';L2'])*ones(2,1)+mm';
x23=inv([L3';L2'])*ones(2,1)+mm';
x13=inv([L3';L1'])*ones(2,1)+mm';
Run Code Online (Sandbox Code Playgroud)

您可以使用查看结果

imshow(bw,'border','tight'); 
hold all; 
%// plot the lines
ezplot(gca, @(x,y) L1(1)*(x-mm(1))+L1(2)*(y-mm(2))-1, [1 340 1 352]);
ezplot(gca, @(x,y) L2(1)*(x-mm(1))+L2(2)*(y-mm(2))-1, [1 340 1 352]);
ezplot(gca, @(x,y) L3(1)*(x-mm(1))+L3(2)*(y-mm(2))-1, [1 340 1 352]);
%// plot the intersection points
scatter([x12(1) x23(1) x13(1)],[x12(2) x23(2) x13(2)],50,'+r');
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述