我有一个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和thetaas和r来沿着弧线进行插值(我只是假设它是一个圆弧,因为它是一个球体)。
我实际上对此进行了一些搜索并将这些代码汇总在一起进行插值,但我无法验证它的工作原理。主要是因为大多数都是从类似的问题中复制和修改的。
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
答案 0 :(得分:0)
您想要创建球形坐标网格,将其转换为笛卡儿坐标,然后使用interp3
在这些坐标处查找图像值,而不是创建一个cartedian坐标网格并将其转换为球面坐标。
球面坐标网格可能类似于meshgrid(0:maxR,0:phiStep:2*pi,0:thetaStep:pi)
。