avw2brainstorm - Convert Analyze struct into BrainStorm file avw2brainstorm(avw,[segment],[scalp],[PCS],[comment]) This function saves a brainstorm file with a name that combines avw.fileprefix with _subjectimage.mat - for example, if avw.fileprefix is set to 'subject01', this function will output a brainstorm MRI file, in the current working directory, called 'subject01_subjectimage.mat' avw - Analyze data loaded by avw_img_read. segment - a sparse 3D matrix the same size as avw.img, with zeros (not brain) and other integer flags to indicate different tissue types (as yet unknown values!) scalp - an Nx3 series of vertex points on the scalp, with coordinates in the Patient Coordinate System (PCS). PCS - a struct with the fields described below comment - a char array describing the image PCS contains the following fields: PCS.R % [3x3 double] rotations from PCS to MRI PCS.t % [3x1 double] translations from PCS to MRI PCS.Comment % a char array describing the PCS % orientation (always 'Neuromag 122' here) PCS.PCSFiducial % [3x4 double] of electrode fiducials PCS.CubeFiducial % [3x4 double] of MRI fiducials PCS.FiducialName = {'Nasion' 'LeftEar' 'RightEar' 'Origin'}; see also AVW_VIEW & ELEC_COREGISTER to obtain fiducials and calculate T, where PCS.R = T(1:3;1:3) and PCS.t = T(4,1:3). See http://neuroimage.usc.edu/ for more information about brainstorm, including a download PDF of the file formats.
0001 function avw2brainstorm(avw,Segment,Scalp,PCS,Comment) 0002 0003 % avw2brainstorm - Convert Analyze struct into BrainStorm file 0004 % 0005 % avw2brainstorm(avw,[segment],[scalp],[PCS],[comment]) 0006 % 0007 % This function saves a brainstorm file with a name that combines 0008 % avw.fileprefix with _subjectimage.mat - for example, if 0009 % avw.fileprefix is set to 'subject01', this function will 0010 % output a brainstorm MRI file, in the current working 0011 % directory, called 'subject01_subjectimage.mat' 0012 % 0013 % avw - Analyze data loaded by avw_img_read. 0014 % segment - a sparse 3D matrix the same size as avw.img, with 0015 % zeros (not brain) and other integer flags to indicate 0016 % different tissue types (as yet unknown values!) 0017 % scalp - an Nx3 series of vertex points on the scalp, with 0018 % coordinates in the Patient Coordinate System (PCS). 0019 % PCS - a struct with the fields described below 0020 % comment - a char array describing the image 0021 % 0022 % PCS contains the following fields: 0023 % 0024 % PCS.R % [3x3 double] rotations from PCS to MRI 0025 % PCS.t % [3x1 double] translations from PCS to MRI 0026 % PCS.Comment % a char array describing the PCS 0027 % % orientation (always 'Neuromag 122' here) 0028 % PCS.PCSFiducial % [3x4 double] of electrode fiducials 0029 % PCS.CubeFiducial % [3x4 double] of MRI fiducials 0030 % PCS.FiducialName = {'Nasion' 'LeftEar' 'RightEar' 'Origin'}; 0031 % 0032 % see also AVW_VIEW & ELEC_COREGISTER to obtain fiducials and 0033 % calculate T, where PCS.R = T(1:3;1:3) and PCS.t = T(4,1:3). 0034 % 0035 % See http://neuroimage.usc.edu/ for more information about 0036 % brainstorm, including a download PDF of the file formats. 0037 % 0038 0039 % $Revision: 1.1 $ $Date: 2004/11/12 01:30:25 $ 0040 0041 % Licence: GNU GPL, no express or implied warranties 0042 % Author: 10/2002, Darren.Weber@flinders.edu.au 0043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0044 0045 fprintf('AVW2BRAINSTORM...\n'); tic 0046 0047 if ~exist('avw','var'), 0048 msg = sprintf('...no input avw - see help avw2brainstorm\n'); 0049 error(msg); 0050 end 0051 0052 fprintf('...converting avw to brainstorm variables\n'); 0053 0054 Cube = uint8(avw.img); 0055 0056 Voxsize = double(avw.hdr.dime.pixdim(2:4)); 0057 0058 if ~exist('Comment','var'), 0059 if isfield(avw,'fileprefix'), 0060 Comment = avw.fileprefix; 0061 else 0062 Comment = ''; 0063 end 0064 end 0065 0066 if ~exist('Segment','var'), Segment = []; end 0067 0068 if ~exist('Scalp','var'), Scalp = []; end 0069 0070 if ~exist('PCS','var'), 0071 PCS.R = eye(3); % [3x3 double] rotations 0072 PCS.t = zeros(3,1); % [3x1 double] translations 0073 PCS.Comment = 'Neuromag 122'; 0074 PCS.PCSFiducial = []; % [3x4 double] 0075 PCS.CubeFiducial = []; % [3x4 double] 0076 PCS.FiducialName = {'Nasion' 'LeftEar' 'RightEar' 'Origin'}; 0077 else 0078 PCS.Comment = 'Neuromag 122'; 0079 end 0080 0081 savename = sprintf('%s_subjectimage.mat',avw.fileprefix); 0082 0083 fprintf('...saving brainstorm variables to %s\n', savename); 0084 0085 save(savename,'Cube','Voxsize','Comment','Segment','Scalp','PCS'); 0086 0087 t=toc; fprintf('...done (%5.2f sec).\n\n',t); 0088 0089 return