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$
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 if length(dm)==2, dm = [dm 1]; end % handling case of 2D image
0032 n_vox = prod(dm(1:3));
0033 
0034 if length(dm) == 3
0035     n_vol = 1;
0036 else
0037     n_vol = dm(4);
0038 end
0039 
0040 % get the data
0041 if nargin==3
0042     data_range = (br(1)-1)*bs+1:min(br(end)*bs,n_vox);
0043 else
0044     data_range = bs;
0045 end
0046 
0047 block=zeros(length(data_range),length(N));
0048 if n_vol==1
0049     for i=1:length(N)
0050         block(:,i) = N(i).dat(data_range);
0051     end
0052 else
0053     for i=1:n_vol
0054         dat_r = N(1).dat(:,:,:,i);
0055         block(:,i) = dat_r(data_range);
0056     end
0057 end
0058 return

Generated on Tue 10-Feb-2015 18:16:33 by m2html © 2005