Be the first to rate this file! 43 downloads (last 30 days) File Size: 4.21 KB File ID: #24177

3D interpolation

by Andriy Myronenko

 

18 May 2009

Code covered by BSD License  

Fast 3D linear interpolation of scalar or vector valued 3D images.

Download Now | Watch this File

File Information
Description

mirt3D_mexinterp is fast mex version of Matlab's interp3 function.
It also allows to interpolate vector valued 3D images or a sequence (video) of 3D images simultaneously.

Compile:
mex mirt3D_mexinterp.cpp

Usage:
 Output_image = mirt3D_mexinterp(Input_image, XI,YI,ZI)

Interpolates the 3D image 'Input_image' at the points with coordinates X,Y,Z. Input_image is assumed to be defined at a regular grid 1:N, 1:M, 1:K, where [M,N,K]=size(Input_image). Points outside the boundary return NaNs. This is equivalent (but much faster) to Matlab's:
 Output_image = interp3(Input_image,XI,YI,ZI,'linear',NaN);

Also you can interpolate a stack of 3D images at the same time:

 Output_images = mirt3D_mexinterp(Input_images, XI,YI,ZI).

where 'Input_images' can be a stack of many 3D images (4D).
The function interpolates each of the 3D images at X,Y,Z coordinates and return a stack of corresponding interpolated images. This is equivalent to Matlab's
 
   Input_images(:,:,:,1)=Input_image1;
   Input_images(:,:,:,2)=Input_image2;
   Input_images(:,:,:,3)=Input_image3;
   Input_images(:,:,:,4)=Input_image4;
  
   Output_images(:,:,:,1) = interp3(Input_image1,XI,YI,ZI,'linear',NaN);
   Output_images(:,:,:,2) = interp3(Input_image2,XI,YI,ZI,'linear',NaN);
   Output_images(:,:,:,3) = interp3(Input_image3,XI,YI,ZI,'linear',NaN);
   Output_images(:,:,:,4) = interp3(Input_image4,XI,YI,ZI,'linear',NaN);
 
This is especially useful for vector valued 3D images, RGB images, to interpolate the whole 3D video at the same coordinates or to interpolate image and its gradients at the same time (e.g. in image registration). For vector valued images, the extra speed gain is from the precomputation of coefficients common for all images in the stack.

While submitting this function, I've noticed another mex implementation of 3D interpolation by Brian (ba_interp3) matlab exchange ID: 21702. His function has similar fast performance, with a slight advantage of mirt3D_mexinterp especially for vector valued images. Note, that ba_interp3 also allows nearest and cubic interpolations, and puts the closest points outside the boundaries.

Enjoy and leave a comment. Also see more at my
homepage: http://www.bme.ogi.edu/~myron/

MATLAB release MATLAB 7.4 (R2007a)
Zip File Content  
Other Files license.txt,
mirt3D_mexinterp.cpp,
mirt3D_mexinterp.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
interp3 Andriy Myronenko 19 May 2009 10:30:07
interpolation Andriy Myronenko 19 May 2009 10:30:07
3d interpolations Andriy Myronenko 19 May 2009 10:30:07
volume interpolation Andriy Myronenko 19 May 2009 10:30:07
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com