如何定义 3 个维度的功率谱?
how to define power spectrum across 3 dimensions?
我正在尝试将一些现有的 matlab 代码从 2 维修改为 3 维,并将 运行 修改为概念块。原始脚本通过对功率谱和随机噪声的乘积进行 运行 ifft(3) 从 2d 随机噪声生成分形。为了定义功率谱,我必须定义 U、V 和 W 维度的频率。
我对 W 维频率与 U 和 V 的关系应该是什么样子有一个心理障碍。显然它们不只是 U 或 V 的转置。在开头包含了一些额外的代码如果它有助于澄清事情,就结束。 var powerspectrum 当前返回一个 2d 矩阵,它应该是 3d。谢谢!
beta = -2;
imsize = [sidelength, sidelength, sidelength]; %length of sides of image in pixels;
% Generate the grid of frequencies. u is the set of frequencies along the first dimension
u = [(0:floor(imsize(1)/2)) -(ceil(imsize(1)/2)-1:-1:1)]'/imsize(1); % First quadrant are positive frequencies. Zero frequency is at u(1,1).
u = repmat(u,1,imsize(2)); % Reproduce these frequencies along ever row.
v = [(0:floor(imsize(2)/2)) -(ceil(imsize(2)/2)-1:-1:1)]/imsize(2); % v is the set of frequencies along the second dimension. For a square region it will be the transpose of u.
v = repmat(v,imsize(1),1); % Reproduce these frequencies along ever column.
w = [(0:floor(imsize(3)/2)) -(ceil(imsize(3)/2)-1:-1:1)]/imsize(3); % W is the set of frequencies along the *third* dimension.
w = repmat(w,imsize(3),1); % Reproduce these frequencies along every PAGE.
powerspectrum = (u.^2 + v.^2 + w.^2).^(beta/2); % Generate the power spectrum
phases = randn(imsize); % Generate a grid of random phase shifts
complexpattern = ifftn(powerspectrum.^0.5 .* (cos(2*pi*phases)+1i*sin(2*pi*phases))); % Inverse Fourier transform to obtain the the spatial pattern
您可以 reshape
u
, v
and w
into [sidelength 1 1]
, [1 sidelength 1]
and [1 1 sidelength]
arrays respectively and let implicit expansion
代替使用 repmat
来完成它的工作并创建一个 [sidelength sidelength sidelength]
数组:
u = [(0:floor(imsize(1)/2)) -(ceil(imsize(1)/2)-1:-1:1)]'/imsize(1);
u = reshape(u,[],1)
v = [(0:floor(imsize(2)/2)) -(ceil(imsize(2)/2)-1:-1:1)]/imsize(2);
v = reshape(v,1,[]);
w = [(0:floor(imsize(3)/2)) -(ceil(imsize(3)/2)-1:-1:1)]/imsize(3);
w = reshape(w,1,1,[]);
powerspectrum = (u.^2 + v.^2 + w.^2).^(beta/2);
phases = randn(imsize);
complexpattern = ifftn(powerspectrum.^0.5 .* (cos(2*pi*phases)+1i*sin(2*pi*phases)));
我正在尝试将一些现有的 matlab 代码从 2 维修改为 3 维,并将 运行 修改为概念块。原始脚本通过对功率谱和随机噪声的乘积进行 运行 ifft(3) 从 2d 随机噪声生成分形。为了定义功率谱,我必须定义 U、V 和 W 维度的频率。
我对 W 维频率与 U 和 V 的关系应该是什么样子有一个心理障碍。显然它们不只是 U 或 V 的转置。在开头包含了一些额外的代码如果它有助于澄清事情,就结束。 var powerspectrum 当前返回一个 2d 矩阵,它应该是 3d。谢谢!
beta = -2;
imsize = [sidelength, sidelength, sidelength]; %length of sides of image in pixels;
% Generate the grid of frequencies. u is the set of frequencies along the first dimension
u = [(0:floor(imsize(1)/2)) -(ceil(imsize(1)/2)-1:-1:1)]'/imsize(1); % First quadrant are positive frequencies. Zero frequency is at u(1,1).
u = repmat(u,1,imsize(2)); % Reproduce these frequencies along ever row.
v = [(0:floor(imsize(2)/2)) -(ceil(imsize(2)/2)-1:-1:1)]/imsize(2); % v is the set of frequencies along the second dimension. For a square region it will be the transpose of u.
v = repmat(v,imsize(1),1); % Reproduce these frequencies along ever column.
w = [(0:floor(imsize(3)/2)) -(ceil(imsize(3)/2)-1:-1:1)]/imsize(3); % W is the set of frequencies along the *third* dimension.
w = repmat(w,imsize(3),1); % Reproduce these frequencies along every PAGE.
powerspectrum = (u.^2 + v.^2 + w.^2).^(beta/2); % Generate the power spectrum
phases = randn(imsize); % Generate a grid of random phase shifts
complexpattern = ifftn(powerspectrum.^0.5 .* (cos(2*pi*phases)+1i*sin(2*pi*phases))); % Inverse Fourier transform to obtain the the spatial pattern
您可以 reshape
u
, v
and w
into [sidelength 1 1]
, [1 sidelength 1]
and [1 1 sidelength]
arrays respectively and let implicit expansion
代替使用 repmat
来完成它的工作并创建一个 [sidelength sidelength sidelength]
数组:
u = [(0:floor(imsize(1)/2)) -(ceil(imsize(1)/2)-1:-1:1)]'/imsize(1);
u = reshape(u,[],1)
v = [(0:floor(imsize(2)/2)) -(ceil(imsize(2)/2)-1:-1:1)]/imsize(2);
v = reshape(v,1,[]);
w = [(0:floor(imsize(3)/2)) -(ceil(imsize(3)/2)-1:-1:1)]/imsize(3);
w = reshape(w,1,1,[]);
powerspectrum = (u.^2 + v.^2 + w.^2).^(beta/2);
phases = randn(imsize);
complexpattern = ifftn(powerspectrum.^0.5 .* (cos(2*pi*phases)+1i*sin(2*pi*phases)));