是否有用于在散点图中定位死区的 Octave 函数或通用解决方案?

问题描述

我在 Octave 中处理大约 50 万个点的数据图。我试图找到数据中空白空间的中心(故意)。

我知道要查找多少个点,我正在考虑在起始位置提供数据,然后尝试在一个方向上扩展一个圆圈,直到您找到有效的数据点位置,然后继续在几个方向上这样做,直到您有一个圆圈没有填充数据但触及有效数据点。该圆的中心将是虚空空间的中心。我不完全确定如何编写它,因为我在编码方面非常绿色。

显然,图形解决方案可能不是最好的方法,但我不知道如何在巨大的 x y 位置矩阵中找到较大的 x 和 y 间隙。

A section of the data I deal with. Trying to write a program to automatically find the center of that hole.

A sample of the data I'm working with. Each data point is an x and y location with a z height that isn't really valuable to what I'm trying to solve here. The values do not line up in consistent intervals

Here is a large sample of what I'm working with

解决方法

我知道你说过你的数据没有在 x 或 y 中排列,但它看起来仍然像网格一样可疑。

在这种情况下,您可能可以将每个网格点表示为图像中的一个“像素”;这使您可以访问可以从 image 包中使用的优秀函数,例如 imregionalmin 函数。在您的情况下,这将为您提供“孔”的连接组件。对于每个组件,您可以通过在该组件内的像素上找到“平均坐标”来轻松找到它们的质心。然后,您可以执行距离变换(例如使用 bwdist)来找到您描述的圆的确切半径,即从该质心到最近像素的距离。或者,您可以从 bwdist 开始,然后使用 immaximas 直接检测质心。如果您有多个这样的区域,您可以使用 bwconncomp 首先查找连接组件(或通过 imregionalmin 的输出)。

如果您的数据不是特别类似于网格,那么您可能可以对数据进行插值以使其适合这样的网格。

示例:

pkg load image
t = 0 : 0.1 : 2 * pi;   % for use when plotting circles later

[X0,Y0] = ndgrid( 1:100,1:100 );               % Create 'index' grid    
X = X0 - 0.25 * Y0;   Y = 0.25 * X0 + Y0;        % Create transformed grid
Z = 0.5 * (X0 - 50) .^ 2 + (Y0 - 50) .^ 2 > 250; % Assign a logical value to each 'index' point on grid

M = imregionalmin ( Z );                        % Find 'hole' as mask
C = { round(mean(X0(M))),round(mean(Y0(M))) }; % Find centre of mass (as index)

R = bwdist( ~M )(C{:});    % Find distance from centre of mass to nearest pixel
R = min( abs( X(C{1}+R,C{2}) - X(C{:}) ),abs( Y(C{1},C{2}+R) - Y(C{:}) ) ); % Adjust for transformed grid

figure(1); hold on
plot( X(Z),Y(Z),'.','markerfacecolor','b' )          % Draw original transformed grid data
plot( X(C{:}),Y(C{:}),'o','r' );   % Draw centre of mass in transformed grid
plot( X(C{:}) + R * cos(t),Y(C{:}) + R * sin(t),'r-' ) % Draw optimal circle on top
axis equal; hold off