Home > bioelectromagnetism > avw_center.m

avw_center

PURPOSE ^

avw_center - find center of a volume

SYNOPSIS ^

function center = avw_center(avw)

DESCRIPTION ^

 avw_center - find center of a volume

 [center] = avw_center(avw)

 avw  - an Analyze 7.5 data struct, see avw_read

 center is the Cartesian coordinates for
 the volume center.  It is a struct with
 coordinates in both voxels and mm (1x3).
 
 center.corner is the result of floor(xdim/2),
 center.abs is the result of (xdim/2).
 
 Finding the center of a voxel based
 volume can be done in several ways.
 
 The absolute center point in a volume will 
 lie either within the center of the middle
 voxel or at the boundary between two voxels
 (depending on whether the volume has an odd
 or even number of voxels in any dimension).
 
 The corner values are the voxel that lies 
 just before the absolute center point of 
 the volume.
 
 The mm coordinates are simply the voxel values
 multiplied by the pixel dimensions.

 Given correctly oriented Analyze 7.5 files, the 
 corner values lie at the right, posterior 
 and inferior corner of the voxel.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function center = avw_center(avw)
0002 
0003 % avw_center - find center of a volume
0004 %
0005 % [center] = avw_center(avw)
0006 %
0007 % avw  - an Analyze 7.5 data struct, see avw_read
0008 %
0009 % center is the Cartesian coordinates for
0010 % the volume center.  It is a struct with
0011 % coordinates in both voxels and mm (1x3).
0012 %
0013 % center.corner is the result of floor(xdim/2),
0014 % center.abs is the result of (xdim/2).
0015 %
0016 % Finding the center of a voxel based
0017 % volume can be done in several ways.
0018 %
0019 % The absolute center point in a volume will
0020 % lie either within the center of the middle
0021 % voxel or at the boundary between two voxels
0022 % (depending on whether the volume has an odd
0023 % or even number of voxels in any dimension).
0024 %
0025 % The corner values are the voxel that lies
0026 % just before the absolute center point of
0027 % the volume.
0028 %
0029 % The mm coordinates are simply the voxel values
0030 % multiplied by the pixel dimensions.
0031 %
0032 % Given correctly oriented Analyze 7.5 files, the
0033 % corner values lie at the right, posterior
0034 % and inferior corner of the voxel.
0035 %
0036 
0037 % $Revision: 1.1 $ $Date: 2004/11/12 01:30:25 $
0038 
0039 % Licence:  GNU GPL, no implied or express warranties
0040 % History:  08/2003, Darren.Weber_at_radiology.ucsf.edu
0041 %
0042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0043 
0044 version = '[$Revision: 1.1 $]';
0045 fprintf('\nAVW_CENTER [v%s]\n',version(12:16));  tic;
0046 
0047 % Extract info from avw.hdr
0048 xdim = double(avw.hdr.dime.dim(2));
0049 ydim = double(avw.hdr.dime.dim(3));
0050 zdim = double(avw.hdr.dime.dim(4));
0051 
0052 xpix = double(avw.hdr.dime.pixdim(2));
0053 ypix = double(avw.hdr.dime.pixdim(3));
0054 zpix = double(avw.hdr.dime.pixdim(4));
0055 
0056 % Find center voxel of volume
0057 center.corner.voxels = zeros(1,3);
0058 center.corner.voxels(1,1) = floor(xdim/2);
0059 center.corner.voxels(1,2) = floor(ydim/2);
0060 center.corner.voxels(1,3) = floor(zdim/2);
0061 
0062 % Find mm coordinates of that voxel
0063 center.corner.mm = zeros(1,3);
0064 center.corner.mm(1,1) = center.corner.voxels(1,1) .* xpix;
0065 center.corner.mm(1,2) = center.corner.voxels(1,2) .* ypix;
0066 center.corner.mm(1,3) = center.corner.voxels(1,3) .* zpix;
0067 
0068 % Find center voxel of volume
0069 center.abs.voxels = zeros(1,3);
0070 center.abs.voxels(1,1) = xdim/2;
0071 center.abs.voxels(1,2) = ydim/2;
0072 center.abs.voxels(1,3) = zdim/2;
0073 
0074 % Find mm coordinates of that voxel
0075 center.abs.mm = zeros(1,3);
0076 center.abs.mm(1,1) = center.abs.voxels(1,1) .* xpix;
0077 center.abs.mm(1,2) = center.abs.voxels(1,2) .* ypix;
0078 center.abs.mm(1,3) = center.abs.voxels(1,3) .* zpix;
0079 
0080 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003