【问题标题】:How to reshape 3D derivatives matrices to 3x3xn matrix?如何将 3D 导数矩阵重塑为 3x3xn 矩阵?
【发布时间】:2014-03-16 18:53:34
【问题描述】:

我有 513x512x200 图像 Dxx、Dyx、Dyy、Dxz、Dzz、Dzy 的 3D 导数 其中 512x512 是 200 张图像的图像尺寸。 现在我想使用可以采用 3x3xn 矩阵的eig3 如何将这些矩阵重塑为 3x3xn 矩阵?

编辑

n 应该是体素的数量,3x3 矩阵应该是这样的

Dxx Dxy Dxz

Dyx Dyy Dyz

Daz Dzy Dzz

【问题讨论】:

  • 那么,输入是一组 200 张图像,每张图像的尺寸为 512x512?由于 512 不能被 3 整除,我假设您想在高度和宽度上最多使用 510?假设您有 510x510 大小的图像,而您的体素是 3x3,那么这意味着我们在每张图像中将有 170x170 体素?每个体素都有 eig3 3x1 向量,因此我们将有 170X170x3 eig3 向量。那么,您希望如何存储它们?请尽可能多地解释。除非您尝试以更好的方式解释,否则我们无能为力。
  • 我基本上想形成每个体素en.wikipedia.org/wiki/Hessian_matrix 的哈斯矩阵,所以我计算了图像的 dxx、dxy 等以形成 hessian 矩阵,但我分别得到了每个导数(即 Dxx 是512x512x 图像数量)为了使用我提到的 eig,它需要 3x3xn,所以 n 是体素的数量,3x3 是这个体素的 Hessian 矩阵
  • 所以我在问如何为 eig 函数准备输入矩阵
  • 如果不清楚,再次抱歉:)

标签: matlab matrix


【解决方案1】:

矩阵的操作可以通过使用'permute'和'reshape'来实现,如下所示。

 % 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]);

享受吧!

【讨论】:

  • 谢谢腾,但是如何格式化 Ds 矩阵?
【解决方案2】:

也许你正在寻找这样的东西 -

%%// 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

【讨论】:

  • 非常感谢 Divakar,我认为它会起作用,但我应该如何将它们收集在一个矩阵中以获得每个体素的 3x3 矩阵形式?
  • 每个 3x3 矩阵将创建 3x1 特征向量。这就是OUT 的大小为 Mx(N/3)xP 的原因。你究竟希望你的输出是多少?你输出的size 必须是什么?请详细解释一下?
  • 如何将导数收集到 IN 矩阵中:)?抱歉,我对 MATLAB 有点陌生
  • 参见 Edit-1。在这里使用循环以确保安全。希望这能让你更接近你的目标!
猜你喜欢
  • 2011-01-16
  • 2016-11-08
  • 1970-01-01
  • 1970-01-01
  • 2023-01-25
  • 1970-01-01
  • 1970-01-01
  • 2021-09-14
  • 2013-05-17
相关资源
最近更新 更多