0001 function [info, status] = spike_check(sinfo, inpath, outpath, scan_offset, nvox, sc)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 status = 0;
0033
0034 nsub = length(sinfo);
0035
0036 if nargin < 2
0037 inpath = './';
0038 outpath = './';
0039 elseif nargin < 3
0040 outpath = './';
0041 end
0042
0043 if nargin < 4
0044 scan_offset = 0;
0045 end
0046
0047 if nargin < 5
0048 nvox = [15 15 2];
0049 end
0050
0051 if isempty(outpath)
0052 outpath = './';
0053 end
0054
0055 if isempty(inpath)
0056 inpath = './';
0057 end
0058
0059 if nargin < 6
0060 sc.nstd = 1;
0061 end
0062
0063 for isub = 1:nsub
0064
0065 s = sinfo(isub);
0066 subj_root = s.id;
0067
0068 info(isub).id = s.id;
0069
0070 num_epi = 0;
0071 for iexam = 1:s.nexams
0072
0073 exam_root = sprintf('%05d', s.exam_nums(iexam));
0074 datapath = fullfile(inpath, subj_root, exam_root);
0075
0076 series=s.series_mappings{iexam};
0077 nseries= size(series,1);
0078
0079 for mapping_idx = 1:nseries
0080 indir = fullfile(datapath, char(series(mapping_idx,1)));
0081
0082 switch char(series(mapping_idx,2))
0083 case {'epi','epi1','epi2','epi3','epi4','epi_12','epi_34'}
0084
0085
0086
0087 if size(series,2) == 3
0088 nruns = length(series{mapping_idx,3});
0089 multi_epi_series = 1;
0090 else
0091 nruns = length(s.cond_order);
0092 multi_epi_series = 0;
0093 end
0094
0095
0096 firstfile = fullfile(indir,'I.001');
0097
0098
0099 [su_hdr,ex_hdr,se_hdr,im_hdr,pix_hdr,im_offset] = GE_readHeader(firstfile);
0100
0101 nX = im_hdr.imatrix_X;
0102 nY = im_hdr.imatrix_Y;
0103 nZ = im_hdr.slquant;
0104 volSize = [nX nY nZ];
0105
0106
0107 imageVol = zeros(nX,nY,nZ);
0108
0109 xa = floor(nX/2-nvox(1));
0110 xb = ceil(nX/2+nvox(1));
0111 ya = floor(nY/2-nvox(2));
0112 yb = ceil(nY/2+nvox(2));
0113 za = floor(nZ/2-nvox(3));
0114 zb = ceil(nZ/2+nvox(3));
0115 nx = xb-xa+1;
0116 ny = yb-ya+1;
0117 nz = zb-za+1;
0118 subVol = zeros(nx,ny,nz);
0119
0120
0121 for irun = 1:nruns
0122 num_epi = num_epi+1;
0123
0124 if multi_epi_series
0125 nvol = s.nvol(series{mapping_idx,3}(irun));
0126 else
0127 nvol = s.nvol(irun);
0128 end
0129
0130 info(isub).exam{num_epi} = exam_root;
0131 info(isub).series{num_epi} = char(series(mapping_idx,1));
0132 info(isub).run(num_epi) = num_epi;
0133
0134 info(isub).data{num_epi} = zeros(nvol,1);
0135
0136 if multi_epi_series
0137 run_offset = sum(s.nvol(series{mapping_idx,3}(1:irun))) - s.nvol(series{mapping_idx,3}(irun));
0138 else
0139 run_offset = sum(s.nvol(1:irun))-s.nvol(irun);
0140 end
0141
0142 start_num = run_offset+1+scan_offset;
0143
0144 for ivol = 1:nvol
0145 [imageVol, lastfile] = GE_readVolume(indir, start_num + ivol, volSize, 16, ...
0146 im_offset);
0147 subVol = imageVol(xa:xb,ya:yb,za:zb);
0148 info(isub).data{num_epi}(ivol) = mean(subVol(:));
0149 fprintf('runnum = %d\tvolnum = %d\tread %s\n',num_epi, ivol,lastfile);
0150
0151 end
0152
0153
0154
0155
0156 tmp = info(isub).data{num_epi};
0157 info(isub).mean(num_epi) = mean(tmp);
0158 info(isub).std(num_epi) = std(tmp);
0159
0160
0161 tmpdiff = abs(diff(info(isub).data{num_epi}));
0162 badidx = find(tmpdiff > sc.nstd * info(isub).std(num_epi));
0163 info(isub).badidx{num_epi} = badidx;
0164
0165 info(isub).numbad(num_epi) = fix(length(badidx)/2);
0166
0167
0168
0169
0170
0171 end
0172 end
0173 end
0174 end
0175 end