matlab - 如何在 MATLAB 中扩展一组点

标签 matlab image-processing data-fitting

假设我在脸上有标志点,如下:

enter image description here

我想通过选择外下巴标志并扩展它们来计算(估计)它们的上边界,所以我想实现这样的新点: enter image description here

所以我想“遵循”由点 1,2 和 3 生成的曲线,并将等距点放在顶部,以便我可以使用 boundary 函数裁剪图像MATLAB。

我想我需要将二阶多项式拟合到数据点,但我不确定如何。那么我怎样才能生成这些点呢?

感谢您的帮助,

编辑

以下是示例地标集的坐标:

图片: enter image description here

地标(1:3,即左侧):

   x         y  
431.1901  547.9975
438.7422  611.0103
451.4842  668.0488

地标(17:-1:15,即右侧)

   x         y  
876.6581  509.5234
878.1327  568.9854
880.7731  619.5879

编辑2

这是17个下巴地标的完整坐标:

   1.0e+03 *

    1.1974    1.3956
    1.2266    1.5488
    1.2554    1.6876
    1.2766    1.8245
    1.3266    1.9530
    1.4098    2.0648
    1.5420    2.1567
    1.6719    2.2222
    1.8180    2.2444
    1.9585    2.1991
    2.0642    2.1208
    2.1761    2.0351
    2.2575    1.9243
    2.3038    1.7937
    2.3191    1.6580
    2.3376    1.5264
    2.3537    1.3825

最佳答案

您可以使用 File Exchange 中的 fit_ellipse()由奥哈德·加尔创建。

您需要稍微修改它,因此它还会返回您将用于提取数据的绘图句柄。为此,将标题更改为

function [ellipse_t, h] = fit_ellipse( x,y,axis_handle )

并添加

     h = gca;

to the bottom of the file.

然后做

close all;
clear all;
landmarks = [1.1974    1.3956; 1.2266    1.5488; 1.2554    1.6876;
             1.2766    1.8245; 1.3266    1.9530; 1.4098    2.0648
             1.5420    2.1567; 1.6719    2.2222; 1.8180    2.2444
             1.9585    2.1991; 2.0642    2.1208; 2.1761    2.0351
             2.2575    1.9243; 2.3038    1.7937; 2.3191    1.6580
             2.3376    1.5264; 2.3537    1.3825];

[e, h] = fit_ellipse(landmarks(:, 1), landmarks(:, 2), gcf);
ch=get(h,'Children');
x=get(ch,'Xdata');
y=get(ch,'Ydata');
plot(x,y);
hold on;
x_l = landmarks(:, 1);
y_l = landmarks(:, 2);
plot(x_l, y_l);
m = min(landmarks(:, 2)); %Get the smallest y value from your landmarks
y_subset = y(y<m);
x_subset = x(y<m);
plot(x_subset, y_subset, 'r.', 'MarkerSize', 10)
axis equal;

产生

enter image description here

在这里,红点是新的样本点。另请注意,在您的情况下,显然 y 轴是反转的,因为您正在显示图像。但这不会改变代码中的任何内容。

或者,如果速度很重要:注释掉 fit_ellipse() 最底部的绘制部分。将函数头更改为

function [ellipse_t, rotated_ellipse] = fit_ellipse( x,y )

并使用以下代码:

[e, r] = fit_ellipse(landmarks(:, 1), landmarks(:, 2));
x = r(1, :);
y = r(2, :);
x_l = landmarks(:, 1);
y_l = landmarks(:, 2);
m = min(landmarks(:, 2)); %Get the smallest y value from your landmarks
y_subset = y(y<m);
x_subset = x(y<m);

关于matlab - 如何在 MATLAB 中扩展一组点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33928337/

相关文章:

matlab - 如何在 MATLAB 中对数据进行多元正态分布拟合?

matlab - 如何在Matlab中将图像从笛卡尔坐标更改为极坐标?

c++ - 寻找优雅高效的 C++ 矩阵库

matlab - 使用 K 均值聚类准确检测图像中的颜色区域

Gnuplot:在一个图上绘制具有多个拟合的多个数据

python - Scipy 曲线拟合优化不适用于对数刻度值

matlab - 什么是 MATLAB?它会生成可执行文件吗?

matlab - 半正定矩阵的行列式

iphone - 是否有关于如何使用 OpenGL 纹理模糊的教程或简化示例?

opencv - 快速图像阈值