在matlab中对变换的3D图像进行插值或重采样算法,最好是sinc插值

时间:2014-12-18 16:06:29

标签: matlab affinetransform

我有一个3D数据集和一个2D数据集,它是第一个卷的切片。它们处于不同的尺度,分辨率和不同的坐标系中,但我知道仿射变换到世界坐标。然后我想我知道如何应用这些,但是如何使用sinc插值再次从那些变换后的坐标中获取图像?我想学习如何执行此操作/如何工作。下面的第一条评论已经指出我在matlab中执行线性插值的现有函数,但我也想知道如何自己这样做,所以我可以使用sinc插值(和其他)。

我可以对坐标进行舍入,并获得那些最近邻插值的值。我想尽可能少地丢失信息而不管计算时间,我想我应该使用sinc插值。当我有变换后的坐标时,如何制作(例如sinc)插值算法?

例如:

    %%get data
A = rand(200,250,250); % I want to get the slice from this that corresponds to B
B = rand(1200,1200); % I want to get the data from A that corresponds to the same pixels

    %%get coordinates for A
siza = size(A); clear xx;clear yy;clear zz;
[xx,yy,zz] = meshgrid(1:siza(1), 1:siza(2), 1:siza(3));
coora = [xx(:)';yy(:)';zz(:)'; ones(size(zz(:)))'];
    %%get coordinates for B
sizb = size(B); clear xx;clear yy;clear zz;
[xx,yy] = meshgrid(1:sizb(1),1:sizb(2)); zz = zeros(size(xx));
coorb = [xx(:)';yy(:)';zz(:)'; ones(size(zz(:)))'];

    %%define affine transformation matrices
T3d = [-0.02  0.02  1    -88 ;
       -0.98  0    -0.02  130;
        0     0.98 -0.02 -110;
        0     0     0     1  ];
T2d = [-0.2   0     0     126;
        0     0.2  -0.2  -131;
        0     0     2     43 ;
        0     0     0     1  ];

    %%transform A coordinates to world coordinates and world coordinates to B coordinates
cooraInBref = T3d*inv(T2d)*coora;
aslice = zeros(size(B));

    %% then nearest neighbor would go something like this (dont exactly know how to do this either):
cooraInBround = round(cooraInBref);
for idx = 1:length(coorb);
    if cooraInBround(3,idx) == 0
        aslice(cooraInBround(1,idx),cooraInBround(2,idx)) = ...;% dont know how to do this
    end
end
    %% how would I implement sinc interpolation instead of rounding the transformed coordinates

相关问题对我没有任何帮助:

Matlab 3D data interpolation

Nearest-neighbor interpolation algorithm in MATLAB

"Nearest neighbor"-like interpolation in MATLAB

How to apply an affine transformation (4x4 matrix) to ndgrid/meshgrid results?

Interpolating 2D Matrix Data

scattered data interpolation

Python/PIL affine transformation

How do I rotate a 3D matrix by 90 degrees counterclockwise?

Resizing a 3D image (and resampling)

image transformations

准备使用matlab中的函数,如chappjc anonsubmitter85和cape code中的评论所指出的那样:

http://mathworks.com/help/matlab/math/interpolating-scattered-data.html

http://mathworks.com/help/matlab/ref/griddata.html?refresh=true

My other SE question I use to get the affine matrix

根据评论中的建议使用scatInterpolant,链接的问题花了差不多十分钟,导致所有NaN的切片,现在我正在尝试其他方法。

1 个答案:

答案 0 :(得分:2)

我现在开始反过来:获取2d点进行采样,然后将其转换为3d体积,然后使用interp3计算值。它很快,效果很好。此代码仅适用于获取单个切片,但我认为您可以轻松地对其进行调整以获得整个转换后的卷。我仍然不知道如何进行sinc插值。

%% transformation from one image to the other
Affine = inv(T2d)*T3d

%% get coordinates for B
sizb = size(B); clear xx;clear yy;clear zz;
[xx,yy] = meshgrid(1:sizb(1),1:sizb(2)); 
zz = ones(size(xx));
coorb = [xx(:)';yy(:)';zz(:)'; ones(size(zz(:)))'];

%% transformed coordinates
coorb_t = Affine*coorb;
idxX = reshape(coorb_t(:,1), sizb(1), sizb(2), 1);
idxY = reshape(coorb_t(:,2), sizb(1), sizb(2), 1);
idxZ = reshape(coorb_t(:,3), sizb(1), sizb(2), 1);

%% interpolate
Asliced = interp3(A, idxX, idxY, idxZ, 'cubic');

仍然不确定我是否应该为Z使用零或。