【发布时间】: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