Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.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_Contour - Fatal编程技术网

如何在matlab中找到轮廓轴的方向?

如何在matlab中找到轮廓轴的方向?,matlab,contour,Matlab,Contour,我想找到用下面的代码绘制的等高线的方向,主轴长度和主轴长度 在我看来,我可能必须使用regionprops命令,但我不知道如何做到这一点。我想找到等高线轴的方向,画出这样的图 我怎样才能完成这项任务?非常感谢您的帮助与其尝试处理轮廓的图形输出,不如建议使用来计算,然后使用x/y点来估计长轴和短轴长度以及方向(对于此,我使用了文件交换提交) 这看起来像下面这样。请注意,我已将输入修改为contourc,因为前两个输入应该是矢量形式,而不是meshgrid的输出 % Compute the th

我想找到用下面的代码绘制的等高线的
方向
主轴长度
主轴长度

在我看来,我可能必须使用
regionprops
命令,但我不知道如何做到这一点。我想找到等高线轴的方向,画出这样的图


我怎样才能完成这项任务?非常感谢您的帮助

与其尝试处理
轮廓的图形输出
,不如建议使用来计算,然后使用x/y点来估计长轴和短轴长度以及方向(对于此,我使用了文件交换提交)

这看起来像下面这样。请注意,我已将输入修改为
contourc
,因为前两个输入应该是矢量形式,而不是
meshgrid
的输出

% Compute the three contours for your data
contourmatrix = contourc(linspace(-10,10,100), linspace(-10,10,100), z_plat, 3);

% Create a "pointer" to keep track of where we are in the output
start = 1;
count = 1;

% Now loop through each contour
while start < size(contourmatrix, 2)
    value = contourmatrix(1, start);
    nPoints = contourmatrix(2, start);

    contour_points = contourmatrix(:, start + (1:nPoints));

    % Now fit an ellipse using the file exchange
    ellipsedata(count) = fit_ellipse(contour_points(1,:), contour_points(2,:));

    % Increment the start pointer
    start = start + nPoints + 1;
    count = count + 1;
end

orientations = [ellipsedata.phi];
%   0   0   0   

major_length = [ellipsedata.long_axis];
%   4.7175    3.3380    2.1539

minor_length = [ellipsedata.short_axis];
%   4.7172    3.3378    2.1532

与其尝试处理
轮廓的图形输出,我建议使用来计算,然后使用x/y点来估计长轴和短轴长度以及方向(对于此,我使用了文件交换提交)

这看起来像下面这样。请注意,我已将输入修改为
contourc
,因为前两个输入应该是矢量形式,而不是
meshgrid
的输出

% Compute the three contours for your data
contourmatrix = contourc(linspace(-10,10,100), linspace(-10,10,100), z_plat, 3);

% Create a "pointer" to keep track of where we are in the output
start = 1;
count = 1;

% Now loop through each contour
while start < size(contourmatrix, 2)
    value = contourmatrix(1, start);
    nPoints = contourmatrix(2, start);

    contour_points = contourmatrix(:, start + (1:nPoints));

    % Now fit an ellipse using the file exchange
    ellipsedata(count) = fit_ellipse(contour_points(1,:), contour_points(2,:));

    % Increment the start pointer
    start = start + nPoints + 1;
    count = count + 1;
end

orientations = [ellipsedata.phi];
%   0   0   0   

major_length = [ellipsedata.long_axis];
%   4.7175    3.3380    2.1539

minor_length = [ellipsedata.short_axis];
%   4.7172    3.3378    2.1532

谢谢@Suever。这有助于我实现我的想法。 我在代码中添加了一些行:

clear
[X1 , X2] = meshgrid(linspace(-10,10,100),linspace(-10,10,100));
mu = [-1,0];
a = [3,2;1,4];
a = a * a';
sigm = a;
xx_size = length(mu);
tem_matrix = ones(size(X1));

x_mesh= cell(1,xx_size);
for i = 1 : xx_size
    x_mesh{i} = tem_matrix * mu(i);
end
x_mesh= {X1,X2};
temp_mesh = [];
for i = 1 : xx_size
    temp_mesh = [temp_mesh x_mesh{i}(:)];
end
Z = mvnpdf(temp_mesh,mu,sigm);
z_plat = reshape(Z,size(X1));
figure;contour(X1, X2, z_plat,3, 'LineWidth', 2,'color','m');
hold on;

% Compute the three contours for your data
contourmatrix = contourc(linspace(-10,10,100), linspace(-10,10,100), z_plat, 3);
% Create a "pointer" to keep track of where we are in the output
start = 1;
count = 1;
% Now loop through each contour
while start < size(contourmatrix, 2)
    value = contourmatrix(1, start);
    nPoints = contourmatrix(2, start);
    contour_points = contourmatrix(:, start + (1:nPoints));
    % Now fit an ellipse using the file exchange
    ellipsedata(count) = fit_ellipse(contour_points(1,:), contour_points(2,:));
    % Increment the start pointer
    start = start + nPoints + 1;
    count = count + 1;
end

orientations = [ellipsedata.phi];  
major_length = [ellipsedata.long_axis];
minor_length = [ellipsedata.short_axis];
tet = orientations(1);
x1 = mu(1);
y1 = mu(2);
a = sin(tet) * sqrt(major_length(1));
b = cos(tet) * sqrt(major_length(1));
x2 = x1 + a;
y2 = y1 + b;

line([x1, x2], [y1, y2],'linewidth',2);

tet = ( pi/2 + orientations(1) );
a = sin(tet) * sqrt(minor_length(1));
b = cos(tet) * sqrt(minor_length(1));
x2 = x1 + a;
y2 = y1 + b;
line([x1, x2], [y1, y2],'linewidth',2);
清除
[X1,X2]=meshgrid(linspace(-10,10100),linspace(-10,10100));
mu=[-1,0];
a=[3,2;1,4];
a=a*a';
sigm=a;
xx_尺寸=长度(μ);
tem_矩阵=个(尺寸(X1));
x_网格=单元(1,xx_大小);
对于i=1:xx_尺寸
x_mesh{i}=tem_矩阵*mu(i);
结束
x_网格={X1,X2};
温度网格=[];
对于i=1:xx_尺寸
temp_mesh=[temp_mesh x_mesh{i}(:)];
结束
Z=mvnpdf(温度网格,μ,sigm);
z_plat=重塑(z,尺寸(X1));
图形轮廓(X1,X2,z_平台,3,'线宽',2,'颜色','m');
等等
%计算数据的三条等高线
轮廓矩阵=轮廓C(邻域(-10,10100),邻域(-10,10100),z_plat,3);
%创建一个“指针”来跟踪我们在输出中的位置
开始=1;
计数=1;
%现在循环通过每个轮廓
开始时<尺寸(轮廓矩阵,2)
值=轮廓矩阵(1,开始);
nPoints=轮廓矩阵(2,开始);
轮廓点=轮廓矩阵(:,开始+(1:nPoints));
%现在使用文件交换来拟合椭圆
椭圆数据(计数)=拟合椭圆(轮廓点(1,:),轮廓点(2,:);
%递增开始指针
start=start+nPoints+1;
计数=计数+1;
结束
方向=[ellipsedata.phi];
长轴长度=[ellipsedata.长轴];
短轴长度=[ellipsedata.短轴];
tet=方向(1);
x1=mu(1);
y1=mu(2);
a=正弦(tet)*sqrt(主长度(1));
b=cos(tet)*sqrt(主长度(1));
x2=x1+a;
y2=y1+b;
线([x1,x2],[y1,y2],'linewidth',2);
tet=(pi/2+取向(1));
a=正弦(tet)*sqrt(小长度(1));
b=cos(tet)*sqrt(小长度(1));
x2=x1+a;
y2=y1+b;
线([x1,x2],[y1,y2],'linewidth',2);

谢谢@Suever。这有助于我实现我的想法。 我在代码中添加了一些行:

clear
[X1 , X2] = meshgrid(linspace(-10,10,100),linspace(-10,10,100));
mu = [-1,0];
a = [3,2;1,4];
a = a * a';
sigm = a;
xx_size = length(mu);
tem_matrix = ones(size(X1));

x_mesh= cell(1,xx_size);
for i = 1 : xx_size
    x_mesh{i} = tem_matrix * mu(i);
end
x_mesh= {X1,X2};
temp_mesh = [];
for i = 1 : xx_size
    temp_mesh = [temp_mesh x_mesh{i}(:)];
end
Z = mvnpdf(temp_mesh,mu,sigm);
z_plat = reshape(Z,size(X1));
figure;contour(X1, X2, z_plat,3, 'LineWidth', 2,'color','m');
hold on;

% Compute the three contours for your data
contourmatrix = contourc(linspace(-10,10,100), linspace(-10,10,100), z_plat, 3);
% Create a "pointer" to keep track of where we are in the output
start = 1;
count = 1;
% Now loop through each contour
while start < size(contourmatrix, 2)
    value = contourmatrix(1, start);
    nPoints = contourmatrix(2, start);
    contour_points = contourmatrix(:, start + (1:nPoints));
    % Now fit an ellipse using the file exchange
    ellipsedata(count) = fit_ellipse(contour_points(1,:), contour_points(2,:));
    % Increment the start pointer
    start = start + nPoints + 1;
    count = count + 1;
end

orientations = [ellipsedata.phi];  
major_length = [ellipsedata.long_axis];
minor_length = [ellipsedata.short_axis];
tet = orientations(1);
x1 = mu(1);
y1 = mu(2);
a = sin(tet) * sqrt(major_length(1));
b = cos(tet) * sqrt(major_length(1));
x2 = x1 + a;
y2 = y1 + b;

line([x1, x2], [y1, y2],'linewidth',2);

tet = ( pi/2 + orientations(1) );
a = sin(tet) * sqrt(minor_length(1));
b = cos(tet) * sqrt(minor_length(1));
x2 = x1 + a;
y2 = y1 + b;
line([x1, x2], [y1, y2],'linewidth',2);
清除
[X1,X2]=meshgrid(linspace(-10,10100),linspace(-10,10100));
mu=[-1,0];
a=[3,2;1,4];
a=a*a';
sigm=a;
xx_尺寸=长度(μ);
tem_矩阵=个(尺寸(X1));
x_网格=单元(1,xx_大小);
对于i=1:xx_尺寸
x_mesh{i}=tem_矩阵*mu(i);
结束
x_网格={X1,X2};
温度网格=[];
对于i=1:xx_尺寸
temp_mesh=[temp_mesh x_mesh{i}(:)];
结束
Z=mvnpdf(温度网格,μ,sigm);
z_plat=重塑(z,尺寸(X1));
图形轮廓(X1,X2,z_平台,3,'线宽',2,'颜色','m');
等等
%计算数据的三条等高线
轮廓矩阵=轮廓C(邻域(-10,10100),邻域(-10,10100),z_plat,3);
%创建一个“指针”来跟踪我们在输出中的位置
开始=1;
计数=1;
%现在循环通过每个轮廓
开始时<尺寸(轮廓矩阵,2)
值=轮廓矩阵(1,开始);
nPoints=轮廓矩阵(2,开始);
轮廓点=轮廓矩阵(:,开始+(1:nPoints));
%现在使用文件交换来拟合椭圆
椭圆数据(计数)=拟合椭圆(轮廓点(1,:),轮廓点(2,:);
%递增开始指针
start=start+nPoints+1;
计数=计数+1;
结束
方向=[ellipsedata.phi];
长轴长度=[ellipsedata.长轴];
短轴长度=[ellipsedata.短轴];
tet=方向(1);
x1=mu(1);
y1=mu(2);
a=正弦(tet)*sqrt(主长度(1));
b=cos(tet)*sqrt(主长度(1));
x2=x1+a;
y2=y1+b;
线([x1,x2],[y1,y2],'linewidth',2);
tet=(pi/2+取向(1));
a=正弦(tet)*sqrt(小长度(1));
b=cos(tet)*sqrt(小长度(1));
x2=x1+a;
y2=y1+b;
线([x1,x2],[y1,y2],'linewidth',2);

与其弄乱图像,为什么不直接使用
轮廓的输出(轮廓矩阵本身)来确定这些东西?@Suever我能从sigma中找到分布轮廓的方向,并用这个方向绘制2条线吗?(对于我的任务,拥有线条的长度并不重要)与其干扰图像,为什么不直接使用
轮廓的输出(轮廓矩阵本身)来确定这些东西呢?@Suever我可以从sigma中找到分布轮廓的方向,并用这个方向绘制2条线?(对于我的任务,拥有行的长度并不重要)