【问题标题】:Spherical interpolation in Matlab from Cartesian Grid笛卡尔网格中 Matlab 中的球面插值
【发布时间】:2018-05-10 04:19:35
【问题描述】:

我有一张 3D 图像。我需要对该图像进行球面波分解,因此我需要将笛卡尔网格中的 3d 图像转换为球坐标。

如果以下内容太长而无法阅读,我想要的要点是我想要一个可以插入球面坐标的映射,这样,尤其是在我的原点附近,我没有很多缺失的信息。

首先,我进行球面转换。

    [ydim,xdim,zdim] = size(myimg);

    [x,y,z] = meshgrid(1:xdim, 1:ydim, 1:zdim);
    x = x - median(x(:)); y = y - median(y(:)); z = z - median(z(:)); 
    [phis, thetas, rs] = cart2sph(x,y,z);

从这里我被卡住了。如何使用我的 phis 和 thetas 以及 r's 沿弧线进行插值(我只是假设它是弧线,因为它是球体)。

我实际上对此进行了一些搜索,并将这段代码放在一起进行插值,但我无法验证它是否有效。主要是因为大部分都是从类似的问题中复制修改而来的。

function [theta0,phi0,rho0] = my_interp(X, Y, Z, nTheta0, nPhi0)
% forget about spherical, let's just interpolate in cartesian then convert 
% to spherical. 
[theta, phi, V] = cart2sph(X, Y, Z);

% X,Y,Z are meshgrid output from above code snippet.
P = [2 1 3];
X = permute(X, P);
Y = permute(Y, P);
Z = permute(Z, P);
V = permute(V, P);

% create a cartesian interpolant, and we'll use it in spherical.
F = griddedInterpolant(X,Y,Z,V);

% prepare grid for meshing (we'll mesh xyz data, not theta,phi)
theta0 = linspace(-pi, pi, nTheta0);
phi0   = linspace(-pi/2, pi/2, nPhi0);
[theta0, phi0] = meshgrid(theta0, phi0);

[x_,y_,z_] = sph2cart(theta0, phi0, 1 ); % !! here is why I get confused. my 
% radius on the sphere is not just 1, I have changing radius. Am I really     
% missing the key insight here? On the other hand, I don't know how to      
% account for all the r's on the image anyways so I can't change this.
rho0 = F(x_,y_,z_);

theta0 = repmat(theta0, 1, 1, size(X, 3));
phi0 = repmat(phi0, 1, 1, size(X, 3));
rho0 = repmat(rho0, 1, 1, size(X, 3));
end

【问题讨论】:

  • SLERP 会为您做正确的事情吗?它基于四元数,它基本上是一种旋转表示,类似于 3D 旋转的虚数。
  • @Dorian ,我将如何在这里应用 SLERP?我想了想,但想不通。 Matlab 有 quatinterp 但如何选择我的 2 个向量?
  • 您必须创建 2 个四元数(不是向量),这将定义您的初始旋转和停止旋转。虽然它不是超级直观。基本上,您需要使用 linspace 更改所有虚数分量,然后将这些四元组转换为您想要的任何值(但请不要使用欧拉角..)

标签: matlab interpolation cartesian-coordinates spherical-coordinate


【解决方案1】:

您想要创建一个球坐标网格,将其转换为笛卡尔坐标,然后使用interp3 查找这些坐标处的图像值,而不是创建一个笛卡尔坐标网格并将其转换为球坐标。

球坐标网格可能类似于meshgrid(0:maxR,0:phiStep:2*pi,0:thetaStep:pi)

【讨论】:

  • 我有一张 50x50x2 的图片。但是 R 上升到 25 (maxR)。然后,当我用 meshgrid(linspace(0,2*pi,180),linspace(0,pi,90),linspace(0,maxR,100)) 执行您所说的操作时,我得到了一个巨大的数组。我的问题是这些的 Z 尺寸(它是 100)。但我认为 100 比 2 并不能解决这个问题。这是插值的本质吗?我的主要问题只是点在原点上的分布不均匀。
  • 我想我不明白你的问题。如果你有一个 50x50x2 的图像,你就没有很多 3rd 维度,我不确定你能从那里得到什么样的 3D 信息。您所说的“点在原点上分布不均”是什么意思?在球坐标中,如果您对较大的 r 进行足够密集的采样,那么您将对较小的 r 进行过采样。起源总是很尴尬:对于 r=0,你会得到所有 phi 和 theta(冗余信息)的恒定值。没有解决办法。
  • 简单地说,我有笛卡尔体素的 f(r,theta,phi)(即 3D 图像的图像像素强度)。这些显然是离散的,我怎样才能得到一个插值,它会给我 f(r,theta',phi') 任意 theta' 和 phi' ?对于涉及 f(r,theta,phi) 的 theta 和 phi,我有一个从 0 到 2pi 和从 0 到 pi 的积分,我需要使用这个插值来进行这种积分。
猜你喜欢
  • 1970-01-01
  • 2011-10-06
  • 1970-01-01
  • 2012-04-07
  • 1970-01-01
  • 2016-01-27
  • 2018-07-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多