【问题标题】:how to plot dot on the ridges of a surface?如何在曲面的脊上绘制点?
【发布时间】:2020-12-13 21:28:29
【问题描述】:

我找不到在表面的上下脊上绘制一些点的方法。 我为表面编写了这段代码:


%initialize parameters
x   = linspace(-2,2,100);
y   = linspace(-2,2,80);
fxy = abs(log(x'.*y));


% it looks like this 
figure(1), clf
surf(x,y,fxy')
shading interp
axis square, rotate3d on
xlabel('X'), ylabel('y'), zlabel('f(x,y)')

为了找到较低的山脊,我写了如下内容:

% find min

minval = min(min(fxy));
[xi,yi] = find( minval == fxy);


idx = sub2ind(size(fxy),xi,yi);

% plot the minimum as a red ball
hold on
plot3(x(xi),y(yi),fxy(idx)','ro', 'MarkerFaceColor','r','MarkerSize',12 )

然后对于下限(下脊),我将阈值设置为 0.1,然后:


% finding lower ridge : points below a threshold of .01

[xi,yi] = find( fxy < minval+.01);

% to get the values,  convert from matrix indices to linear indices
idx = sub2ind(size(fxy),xi,yi);

% plot the close-to minimum points
plot3(x(xi),y(yi),fxy(idx)','ro','markerfacecolor','r','markersize',12)

现在我做到了最大程度:

% finding maximum
maxval = max(max(fxy));
[xi,yi] = find( maxval == fxy);
% plot the maximum as a red ball
plot3(x(xi),y(yi),fxy(xi,yi)','ro', 'MarkerFaceColor','r','MarkerSize',12 )

现在我怎样才能找到上山脊?我将阈值设置为上限 5,结果是这样的:

% finding upper ridge : points below a threshold of 5

[xi,yi] = find( maxval- fxy <5);

% to get the values,  convert from matrix indices to linear indices
idx = sub2ind(size(fxy),xi,yi);

% plot the close-to minimum points
plot3(x(xi),y(yi),fxy(idx)','ro','markerfacecolor','r','markersize',12)


哪个是仅获得上山脊的最佳阈值?有没有其他方法只在上边缘绘制点?

【问题讨论】:

  • 你想获得什么作为“上边缘”?您需要考虑的是,对f(x,y) 使用粗略的水平阈值将导致水平表面上方的所有点(图像中大约为z=3.2)都被标记。如果您想要真正的边缘,这比应用简单的一维阈值要复杂得多。您需要使用我认为的导数以某种方式识别这些边缘。
  • 我不知道你想做什么,但从数学上讲,因为abs(log(0)) = inf 没有“上山脊”这样的东西。因此,突出显示数字伪影很奇怪。

标签: matlab plot min


【解决方案1】:

对于顶部山脊,在一般情况下,我会遵循 Adriaan 的评论并查看导数(您可以使用函数 gradient)。

但是,在您的情况下,还有另一种方法,由于以下事实成为可能:

  • 在表面fxy 的任何X 切片上,山脊y 坐标将与此X 切片的最大值重合。
  • 并且,在表面fxy 的任何Y 切片上,山脊x 坐标将与此Y 切片的最大值重合。

有了这个观察,max 函数就是你所需要的:

% Find maximum Z value and index for
[zxmax,idxzx] = max(fxy) ;          % All X slices (columns)
[zymax,idxzy] = max(fxy,[],2) ;     % All Y slices (rows)

xr = x(idxzx) ; % get the actual X coordinates from the column indices
yr = y(idxzy) ; % get the actual Y coordinates from the row indices

% Display
hold on
plot3(xr,y,zxmax,'r','LineWidth',4)
plot3(x,yr,zxmax,'b','LineWidth',4)

% Or if you want them dotted
% plot3(xr,y,zxmax,'or')
% plot3(x,yr,zymax,'ob')

在您的初始表面显示顶部绘制的这将呈现:

【讨论】:

  • ,太棒了!非常感谢您的直观回答,您知道,我不知道如何使用 deivitive 来查找整个山脊。我知道导数可以给我最大值(最高点),但它如何给出沿山脊的所有点?我应该使用第二个神器还是什么?
  • 每次 Z 方向的信号变化(分别是从上升到下降或下降到上升)时,导数都会改变符号(从正到负,或从负到正)。由于您的山脊正是如此(Z 方向的信号变化),您将尝试寻找导数 = 0 的点(指示方向的变化)。由于域是离散的,因此您可能找不到导数正好是 0 的点,在这种情况下,您将选择最接近 0 的点(在具有不同符号的两个点中)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-20
  • 2017-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多