I have one 3D data set and one 2D data set, which is a slice of the first volume. They are on different scales, resolutions and in a different coordinate system, but as I know the affine transformation to world coordinates. Then I think I know how to apply them, but how can I return an image from these transformed coordinates again using sinc interpolation? I would like to know how to do it / how it works. The first comments below already pointed me to existing functions inside matlab that perform linear interpolation, but I would also like to know how to do it myself, so I can use sinc interpolation (and others).
I can get around the coordinates and get the values for those that will be the nearest neighbor interpolation. I would like to lose as little information as possible, regardless of the computation time, I think I should use interpolation then. When I have the transformed coordinates, how do I make (e.g. sinc) an interpolation algorithm?
eg:
%%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
Related questions that do not help me further:
Matlab 3D data interpolation
Nearest Neighbor Interpolation Algorithm in MATLAB
Nearest Neighbor Interpolation in MATLAB
How to apply affine transformation (4x4 matrix) to ndgrid / meshgrid results?
Interpolate 2D Matrix Data
scattered data interpolation
Python / PIL affinity transformation
How to rotate a 3D matrix 90 degrees counterclockwise?
Resize a 3D image (and resample)
image conversion
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
SE,
Interpolant, , , NaN, .