Transform a 3d volume by using an affine transformation matrix

This function transforms a volume by using an affine transformation matrix.
1.9K Downloads
Updated 17 Oct 2009

View License

This function transforms volume 'old_im' by means of affine transformation matrix 'M'. The output volume can be sub- and oversampled. The function makes use of interp3, so 'nearest', 'linear', 'spline', 'cubic' and fast ( * ) interpolation is possible.

% Usage example - simple translation
load mri.mat
D = squeeze(D(:,:,1,:));
% Create affine transformation matrix, simply shift (x,y) = (50,25)
M = [1 0 0 50; 0 1 0 25; 0 0 1 0; 0 0 0 1];
% Invert M, since the interpolation is backward. Meanwhile subsample the output volume x-direction by a factor of two.
D_new = affine3d(D,inv(M),1:2:128,1:128,1:27);
figure
subplot(1,2,1)
imagesc(D(:,:,10))
title('Original volume')
subplot(1,2,2)
imagesc(D_new(:,:,10))
title('Shifted volume')

Cite As

Martijn Steenwijk (2024). Transform a 3d volume by using an affine transformation matrix (https://www.mathworks.com/matlabcentral/fileexchange/25596-transform-a-3d-volume-by-using-an-affine-transformation-matrix), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0