Skip to content
Snippets Groups Projects
Commit a1e65d6f authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Volume Rotation: added function for rotating volumes along generic axes

parent a5384685
No related branches found
No related tags found
No related merge requests found
function vol = gtRotateVolume(vol, rot_tensor, rot_axis)
if (numel(rot_tensor) == 1)
if (~exist('rot_axis', 'var'))
rot_axis = [0 0 1];
end
rotcomp = gtMathsRotationMatrixComp(rot_axis', 'col');
rot_tensor = gtMathsRotationTensor(rot_tensor, rotcomp);
end
[vol_size(1), vol_size(2), vol_size(3)] = size(vol);
vol_center = (vol_size + 1) / 2;
T1 = eye(4);
T1(4, 1:3) = -vol_center;
T2 = eye(4);
T2(1:3, 1:3) = rot_tensor;
T3 = eye(4);
T3(4, 1:3) = +vol_center;
T = T1 * T2 * T3;
tform = maketform('affine', T);
% new_center = tformfwd(vol_center, tform)
R = makeresampler('linear', 'fill');
vol = tformarray(vol, tform, R, [1 2 3], [1 2 3], vol_size, [], 0);
end
% function vol = gtRotateVolume(vol, angle, method)
% if (~exist('method', 'var'))
% method = 'nearest';
% end
% for ii_s = 1:size(vol, 3)
% vol(:, :, ii_s) = imrotate(vol(:, :, ii_s), angle, method, 'crop');
% end
% end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment