Home > . > prt_load_blocks.m

prt_load_blocks

PURPOSE ^

Load one or more blocks of data.

SYNOPSIS ^

function block = prt_load_blocks(filenames, bs, br)

DESCRIPTION ^

 Load one or more blocks of data.
 This script is a effectively a wrapper function that for the routines
 that actually do the work (SPM nifti routines)

 The syntax is either:

 img = prt_load_blocks(filenames, block_size, block_range) just to specify
 continuous blocks of data

 or

 img = prt_load_blocks(filenames, voxel_index) to access non continuous
 blocks
_______________________________________________________________________
 Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function block = prt_load_blocks(filenames, bs, br)
0002 % Load one or more blocks of data.
0003 % This script is a effectively a wrapper function that for the routines
0004 % that actually do the work (SPM nifti routines)
0005 %
0006 % The syntax is either:
0007 %
0008 % img = prt_load_blocks(filenames, block_size, block_range) just to specify
0009 % continuous blocks of data
0010 %
0011 % or
0012 %
0013 % img = prt_load_blocks(filenames, voxel_index) to access non continuous
0014 % blocks
0015 %_______________________________________________________________________
0016 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory
0017 
0018 % Written by A Marquand
0019 % $Id: prt_load_blocks.m 461 2012-03-20 16:01:53Z schrouff $
0020 
0021 if nargin <2 || nargin >3
0022     disp('Usage: img = prt_load_blocks(filenames, block_size, block_range)');
0023     disp('or')
0024     disp('Usage: img = prt_load_blocks(filenames, voxel_indexes)');
0025     return;
0026 end
0027 
0028 % read the image dimensions from the header
0029 N  = nifti(filenames);
0030 dm = size(N(1).dat);
0031 n_vox = prod(dm(1:3));
0032 
0033 if length(dm) == 3
0034     n_vol = 1;
0035 else
0036     n_vol = dm(4);
0037 end
0038 
0039 % get the data
0040 if nargin==3
0041     data_range = (br(1)-1)*bs+1:min(br(end)*bs,n_vox);
0042 else
0043     data_range = bs;
0044 end
0045 
0046 block=zeros(length(data_range),length(N));
0047 if n_vol==1
0048     for i=1:length(N)
0049         dat_r = reshape(N(i).dat(:,:,:),prod(dm(1:3)),1);
0050         block(:,i) = dat_r(data_range);
0051     end
0052 else
0053     for i=1:n_vol
0054         dat_r=reshape(N(1).dat(:,:,:,i),prod(dm(1:3)),1);
0055         block(:,i) = dat_r(data_range);
0056     end
0057 end
0058 return

Generated on Sun 20-May-2012 13:24:48 by m2html © 2005