0001 function img_stack = interp_no_egis(data,bad_chan,interp_type,plot_res,outfile,header_flag,stack)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 write_images = 1;
0018
0019 if nargin < 1
0020 disp(['Not enough input arguments to interp_no_egis'])
0021 return
0022 elseif nargin < 2
0023 bad_chan = [];
0024 interp_type = '3d';
0025 plot_res = 40;
0026 outfile = 'interp.out';
0027 header_flag = 'h';
0028 stack = 1;
0029 elseif nargin < 3
0030 interp_type = '3d';
0031 plot_res = 40;
0032 outfile = 'interp.out';
0033 header_flag = 'h';
0034 stack = 1;
0035 elseif nargin < 4
0036 plot_res = 40;
0037 outfile = 'interp.out';
0038 header_flag = 'h';
0039 stack = 1;
0040 elseif nargin < 5
0041 write_images = 0;
0042 elseif nargin < 6
0043 header_flag = 'h';
0044 stack = 1;
0045 elseif nargin < 7
0046 stack = 1;
0047 end
0048
0049 if write_images & ~stack
0050 disp(['Only supporting stacked output at this time'])
0051 return
0052 end
0053
0054 if any(size(data) == 1)
0055 nsamps = 1;
0056 else
0057 nsamps = size(data,1);
0058 end
0059
0060 good_chan = ones(1,size(data,2));
0061 if ~isempty(bad_chan)
0062 good_chan(bad_chan) = zeros(size(bad_chan));
0063 end
0064
0065 good_chan = find(good_chan);
0066
0067 [xelec,yelec,zelec] = electrodes(129);
0068
0069 v = zeros(1,size(good_chan,2));
0070 x = zeros(1,size(good_chan,2));
0071 y = zeros(1,size(good_chan,2));
0072 z = zeros(1,size(good_chan,2));
0073
0074 x = xelec(good_chan);
0075 y = yelec(good_chan);
0076 z = zelec(good_chan);
0077
0078 welec = 1;
0079
0080 [k, kinv, a, ainv, e] = k_and_e(welec,x,y,z);
0081
0082 img_stack = zeros(plot_res,plot_res,nsamps);
0083
0084 for isamp = 1:nsamps
0085
0086 disp([' samp: ' int2str(isamp)])
0087
0088 w = data(isamp,:);
0089 v = w(good_chan);
0090
0091 [p,q]= mateqs(welec,x,y,z,v,k,kinv,a,ainv,e);
0092
0093 ruu = sqrt(x(1).^2+y(1).^2+z(1).^2);
0094 [xs,ys,zs] = polgrid(plot_res,ruu);
0095 image_3d= interp_3d(welec,x,y,z,xs,ys,zs,p,q);
0096 imagemat= mask(xs,ys,zs,image_3d,120);
0097
0098 img_stack(:,:,isamp) = imagemat;
0099
0100 if write_images
0101 if isamp == 1
0102 outfname = [outfile '_s' int2str(isamp) '_s' int2str(nsamps)];
0103 outfid = fopen(outfname,'wb','ieee-be');
0104
0105 if header_flag == 'h'
0106 num_written = fwrite(outfid, size(imagemat), 'float');
0107 if num_written ~= 2, error('Failed to write header info'), end
0108 fwrite(outfid, plot_res, 'float');
0109 end
0110 end
0111
0112 num_written = fwrite(outfid,imagemat','float');
0113 if num_written ~= size(imagemat,1)*size(imagemat,2), error('write-out failed'), end
0114 end
0115
0116 end
0117
0118 if write_images
0119 fclose(outfid);
0120 end
0121
0122 return
0123
0124
0125
0126
0127