SPM99 Gem 8: Reslicing images

This is for soley reslicing images, but it has a nice description of how to create a basic transformation matrix.

Subject: Re: how to write out a resampled volume with new user specified
              voxel size
From: John Ashburner <john@FIL.ION.UCL.AC.UK&gt
Date: Thu, 4 Jan 2001 10:57:52 +0000

|       I would like to batch resample some volume images to isotropic
| voxels.  Is there an SPM99 command line instruction (or menu option) that
| would permit me to write out a resampled volume with a user specified voxel
| size dimensions?  I know this core function is implicit in several
| modules.  I considered using Coregister or Spatial Normalization modules
| but these require a target or template volume of the desired resolution
| which doesn't always exist in my application.
|      Many thanks for any suggestions.

You could try the attached function that I've just scribbled together.  It
hasn't been tested, so I hope it works.

Best regards,

The attached function is here reslice.m and below

function reslice(PI,PO,dim,mat,hld)
% FORMAT reslice(PI,PO,dim,mat,hld)
%   PI - input filename
%   PO - output filename
%   dim - 1x3 matrix of image dimensions
%   mat - 4x4 affine transformation matrix mapping
%         from vox to mm (for output image).
%         To define M from vox and origin, then
%             off = -vox.*origin;
%              M   = [vox(1) 0      0      off(1)
%                     0      vox(2) 0      off(2)
%                     0      0      vox(3) off(3)
%                     0      0      0      1];
%   hld - interpolation method.
% @(#)JohnsGems.html	1.42 John Ashburner 05/02/02

VI          = spm_vol(PI);
VO          = VI;
VO.fname    = deblank(PO);
VO.mat      = mat;
VO.dim(1:3) = dim;

VO = spm_create_image(VO); end;
for x3 = 1:VO.dim(3),
        M  = inv(spm_matrix([0 0 -x3 0 0 0 1 1 1])*inv(VO.mat)*VI.mat);
        v  = spm_slice_vol(VI,M,VO.dim(1:2),hld);
        VO = spm_write_plane(VO,v,x3);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s