使用 scipy RBFInterpolate 进行 3D 表面估计

问题描述 投票:0回答:0

我正在尝试使用 scipy RBFInterpolate 中的 RBFInterpolate 函数对 3D 网格进行表面估计。我认为我遇到了完全错误的事情,但我无法弄清楚它是什么。当我在使用函数后绘制估计数据时,它看起来像这样:

黑色散点图是对网格原始数据的下采样,但正如您所见,该函数显然效果不佳。我尝试使用 scipy 中的函数 CloughTocher2DInterpolator 并获得了一些不错的结果,但是我想看看 RBFInterpolation 是否表现更好。 这是 CloughTocher2DInterpolator 的结果:

我用过的代码在这里:

import open3d as o3d
import numpy as np
from scipy.interpolate import CloughTocher2DInterpolator
from scipy.interpolate import RBFInterpolator
import matplotlib.pyplot as plt

mesh = o3d.io.read_triangle_mesh("..pathToMesh.ply")
#mesh = mesh.subdivide_loop(number_of_iterations=3)
samplingNumber = 3600
pcd = mesh.sample_points_uniformly(number_of_points=samplingNumber)
#pcd = mesh.sample_points_poisson_disk(number_of_points=500, pcl=pcd)

#o3d.visualization.draw_geometries([mesh])

## CONVERTING DATA TO NUMPY ARRAYS
points = np.asarray(pcd.points)
x = points[:, 0]
y = points[:, 1]
z = points[:, 2]

## CREATING GRID  & DOWNSAMLING ##
density = np.sqrt(samplingNumber).astype(int)
X = np.linspace(min(x), max(x), num=density)
Y = np.linspace(min(y), max(y), num=density)
X, Y = np.meshgrid(X, Y)  # 2D grid for interpolation

"""
## USING CloughTocher2DInterpolator FUNCTION ##
interp = CloughTocher2DInterpolator(np.array([x, y]).T, z, fill_value=-1.33, tol=1e-03)
Z = interp.__call__(X, Y)
"""

## USING RBFInterpolator FUNCTION ##
xy_points = np.stack([X.ravel(), Y.ravel()], -1) # shape (N, 2) in 2d

rbf = RBFInterpolator(xy_points, z, kernel='cubic', smoothing=0)
Z = rbf.__call__(xy_points).reshape(X.shape)

fig = plt.figure()
ax = plt.axes(projection='3d')

Z_new = Z.reshape(X.shape)
ax.scatter(x, y, z, marker=".", color='black', s=1)
#ax.contour3D(X, Y, Z, 75, cmap='BrBG_r')
#ax.plot_trisurf(x, y, z, cmap='viridis', edgecolor='none')
#ax.plot_wireframe(X, Y, Z, color='black')
ax.plot_surface(X, Y, Z_new, rstride=1, cstride=1, cmap='viridis', edgecolor='none')

ax.set_title('surface')

ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()
matplotlib scipy 3d interpolation mesh
© www.soinside.com 2019 - 2024. All rights reserved.