function images = read_mrimage(dir_name, filter, w, h); % function images = read_mrimage(dir_name, filter, w, h); % % Aug 2003, Farshad Moradi % California Institute of Technology % % Reads analyze image file into matlab. % % Example: % cd E:\MRI\Experiments % images = read_mrimage('LE0002/raw_030618','*', 64, 64); % % DICOM format can be converted to Analyze images % using MRIConvert (http://lcni.uoregon.edu/~jolinda/MRIConvert) % % Wildcards are allowed in filter % % To align the brain before reading the MRI data, use flirt: % drTransform3D.bat % The batch file code is at the end of this file (as comment) % images = []; fname = {}; dir_cont = dir([dir_name '/' filter '.img']); for i=1:length(dir_cont), fname{i} = dir_cont(i).name; end; fname = sort(fname); for i=1:length(fname), fid = fopen( [dir_name '/' fname{i}] ); temp = fread(fid, 'short=>double'); fclose(fid); images(i).name = fname{i}; images(i).nslice = length(temp)/(w*h); images(i).data = reshape(temp, w, h, images(i).nslice); images(i).w = w; images(i).h = h; end; % % drTransform3D.bat: % % % @echo off % % % % REM Usage: % % REM drTransfrom3D % % REM % % % % mkdir T_%1 % % for %%f in (%1\*.hdr) DO set tempfile=%%f % % echo Calculating transfromation matrix using %tempfile% % % flirt -in %tempfile% -ref %2 -dof 7 -omat T_%1.matrix % % echo Applying transfromation % % for %%f in (%1\*.hdr) DO flirt -in %%f -ref %2 -applyxfm -init T_%1.matrix -out T_%%f