Home > eeg > egis > scripts > make_a_image.m

make_a_image

PURPOSE ^

status = make_a_image(data,bad_chan,plot_res,image_rows,image_columns

SYNOPSIS ^

function [image_binary, max_mask] = make_a_image(data,bad_chan,plot_res,image_rows,image_columns,out_root);

DESCRIPTION ^

status = make_a_image(data,bad_chan,plot_res,image_rows,image_columns
,out_root)
data = arbitrary number of rows Nchan columns. 
bad_chan = bad_Chans list e.g [6 7 9]; (optional)
plot_Res = image size e.g 100 (optional) defaults to 100
e.g.
make_a_image(cor_by_obs([1 4],:),[37 68],100)
other optional parameters
image_rows (default is 1)
image_columns (default is size(data,1))
out_root (default is gui) generates file out_root.img

note: thisis the lowest level imaging software, there is probably a higher
level script you should be using

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [image_binary, max_mask] = make_a_image(data,bad_chan,plot_res,image_rows,image_columns,out_root);
0002 %status = make_a_image(data,bad_chan,plot_res,image_rows,image_columns
0003 %,out_root)
0004 %data = arbitrary number of rows Nchan columns.
0005 %bad_chan = bad_Chans list e.g [6 7 9]; (optional)
0006 %plot_Res = image size e.g 100 (optional) defaults to 100
0007 %e.g.
0008 %make_a_image(cor_by_obs([1 4],:),[37 68],100)
0009 %other optional parameters
0010 %image_rows (default is 1)
0011 %image_columns (default is size(data,1))
0012 %out_root (default is gui) generates file out_root.img
0013 %
0014 %note: thisis the lowest level imaging software, there is probably a higher
0015 %level script you should be using
0016 if ~ (nargin ==1|nargin ==2|nargin == 3|nargin == 5|nargin == 6)
0017     error('inappropriate number of input arguments');
0018 end;
0019  
0020 if nargin < 2
0021     bad_chan = [];
0022     plot_res = 100;
0023 end
0024 if nargin < 3
0025     plot_res= 100;
0026 end;
0027 if nargin <  4
0028 image_binary = zeros(plot_res,plot_res*size(data,1));
0029 image_rows = 1;
0030 image_columns = size(data,1);
0031 else
0032 image_binary = zeros(plot_res*image_rows,plot_res*image_columns);
0033 end;
0034 
0035 [xelec,yelec,zelec] = electrodes(size(data,2));
0036 good_chan_mask = ones(1,size(data,2));
0037 
0038 ruu = sqrt(xelec(1).^2+yelec(1).^2+zelec(1).^2);
0039 [xs,ys,zs] = polgrid(plot_res,ruu);
0040 if ~isempty(bad_chan)    
0041 good_chan_mask(1,bad_chan) = zeros(1,size(bad_chan,2));
0042 end;
0043 good_chan = find(good_chan_mask(1,:));
0044 x = zeros(1,size(good_chan,2));
0045 y = zeros(1,size(good_chan,2));
0046 z = zeros(1,size(good_chan,2));
0047 x = xelec(good_chan);
0048 y = yelec(good_chan);
0049 z = zelec(good_chan);
0050 elec = xyz2tp(x,y,z);
0051 max_mask = (180/pi)*max(elec(:,1))-3;
0052 welec = 1;
0053 icount = 1;
0054 [k,kinv,a,ainv,e] = k_and_e(welec,x,y,z);
0055 for i = 1:image_rows
0056     for j = 1:image_columns
0057                w = data(icount,:);
0058                v = zeros(1,size(good_chan,2));
0059         v = w(good_chan);
0060         icount = icount+1;
0061         [p,q,error_check]= mateqs(welec,x,y,z,v,k,kinv,a,ainv,e);
0062         image_3d= interp_3d(welec,x,y,z,xs,ys,zs,p,q);    
0063         imagemat= mask(xs,ys,zs,image_3d,max_mask); 
0064         image_binary(plot_res*(i-1)+1:plot_res*(i-1)+plot_res,plot_res*(j-1)+1:plot_res*j)= imagemat;
0065 end;
0066 end;
0067 if (nargin == 6)
0068     if ~isempty(out_root)
0069         out_fname = [out_root '.img'];
0070         fid = fopen(out_fname,'wb');
0071         if fid < 0
0072             error('couldnt open output file')
0073         end
0074     else
0075         fid = -1;
0076     end
0077 elseif nargin < 6
0078     fid = put_fid('wb');
0079     if fid < 0
0080         error('couldnt open output file')
0081     end
0082 end;
0083 if fid ~= -1
0084     size(image_binary);
0085     num_written = fwrite(fid, size(image_binary), 'float');
0086     if num_written ~= 2
0087             error('Failed to write header info');
0088     end 
0089     fwrite(fid,plot_res,'float');
0090     num_written = fwrite(fid,image_binary','float');
0091     if num_written ~= size(image_binary,1)*size(image_binary,2)
0092         error('write-out filed')
0093     end;
0094     fclose(fid);
0095 end;

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003