我有513x512x200图像Dxx,Dyx,Dyy,Dxz,Dzz,Dzy的3D衍生物
其中512x512是200幅图像的图像尺寸。
现在我想使用可以采用3x3xn矩阵的eig3
我怎样才能将这些矩阵重塑为3x3xn矩阵?
修改
n应该是体素的数量,3x3矩阵应该是
Dxx Dxy Dxz
Dyx Dyy DyzDaz Dzy Dzz
答案 0 :(得分:1)
可以通过使用“permute”来实现对矩阵的操作。和'重塑'如下。
% say you saved your 2nd derivative 3D image as 'Ds'
Ds = [Dxx(:) Dxy(:) Dxz(:) Dyz(:) Dyy(:) Dyz(:) Dzz(:) Dzy(:) Dzz(:)];
% permute
Ds = permute(Ds,[2 1]);
% reshape
n = numel(Dxx);
Ds = reshape(Ds,[3 3 n]);
享受!
答案 1 :(得分:1)
也许你正在寻找这样的东西 -
%%// M and N are the dims of each image and P is the count of images.
%%// Please not that for 3x3 block processing, you would need to make sure that
%%// the width of images are divisble by 3; if they are not, consider cropping or padding.
IN = some_MxNxP_data;
%%// In-code cropping, as mentioned earlier
IN = IN(:,1:3*floor(size(IN,2)/3),:);
%%// Final output would be a complex matrix of size Mx(N/3)xP
OUT = zeros(size(IN,1),size(IN,2)/3);
%%// Main calculation part that uses block processing creating 3x3 blocks and using eig3 on each of them
for k = 1:size(IN,3)
fun1 = @(block_struct) eig3(block_struct.data);
OUT(:,:,k) = blockproc(double(IN(:,:,k)),[3 3],fun1);
end
修改1
<强>代码强>
M = 7; %%// Image height, which must be replaced by actual data, 512 in your case
N = 7; %%// Image width, which must be replaced by actual data, 512 in your case
P = 5; %%// Number of images, which must be replaced by actual data, 200 in your case
%%// Your Dxx,Dyx... data, which is created randomly here, for demo
Dxx= rand(M,N,P);
Dyx= rand(M,N,P);
Daz= rand(M,N,P);
Dxy= rand(M,N,P);
Dyy= rand(M,N,P);
Dzy= rand(M,N,P);
Dxz= rand(M,N,P);
Dyz= rand(M,N,P);
Dzz= rand(M,N,P);
voxel_mat = zeros(3,3,M,N,P);
eig_mat = zeros(M,N,3);
for k0 = 1:P
for k1 = 1:M
for k2 = 1:N
voxel_mat(:,:,k1,k2,k0) = [Dxx(k1,k2,k0) Dxy(k1,k2,k0) Dxz(k1,k2,k0); ...
Dyx(k1,k2,k0) Dyy(k1,k2,k0) Dyz(k1,k2,k0); ...
Daz(k1,k2,k0) Dzy(k1,k2,k0) Dzz(k1,k2,k0)];
eig_mat(k1,k2,:,k0) = eig3(voxel_mat(:,:,k1,k2,k0));
end
end
end