headplot.m

来自「含有多种ICA算法的eeglab工具箱」· M 代码 · 共 797 行 · 第 1/2 页

M
797
字号
% headplot() - plot a spherically-splined EEG field map on a semi-realistic %              3-D head model. Rotate head using left mouse button.% Example:%   >> headplot example   - show an example spherical 'eloc_angles' file%   >> headplot cartesian - show an example cartesian 'eloc_angles' file%% Setup usage (do once):%   >> headplot('setup', elocs, splinefile, 'Param','Value',...);%   (previous call format headplot('setup', elocs, splinefile, cooment, type)%    is still supported)%% Inputs: %   elocs         - file of electrode locations (compatible with readlocs())%                   or channel location structure. If the channel file extension%                   is not standard, use readlocs() to load the data file, e.g.%                   >> headplot('setup', readlocs('myfile', 'filetype', 'besa'), ...%                      'splinefile');%   splinefile    - name of spline file to save splining info into%% Optional Parameters:%   'comment'     - ['string'] optional string vector containing info for spline %                   file.%   'orilocs'     - ['off'|'on'] use original electrode location on the head%                  default: 'off' (extrapolated to spherical). Note that %                  electrode location must be coregisted with the MRI head.%   'meshfile'    - ['string'] Matlab files containing at least 2 variables%                   POS    - vertices 3-D positions, x=left-right; y=back-front, %                            z=up-down%                   TRI1   - faces on which the scalp map should be computed%                   center (optional) - 3-D center of head mesh%                   TRI2   (optional) - faces in skin color%                   NORM   (optional) - normal for each vertex (better shades)%% General usage:%   >> headplot(values,'spline_file','Param','Value',...)%% Inputs:%   values        - vector containing value at each electrode position%   'spline_file' - spline filename computed and saved by running 'setup'%% Optional Parameters:%   'meshfile'   - [string] mesh file name. See file content in the setup%                  description. By default uses the template EEGLAB file.%   'electrodes' - ['on'|'off'] -> show electrode positions {default 'on'}%   'title'      -  Plot title {default none}%   'labels'     -  2 -> plot stored electrode labels;%                   1 -> plot channel numbers; 0 -> no labels {default}%   'cbar'       -  0 -> Plot colorbar {default: no colorbar}%                   H -> Colorbar axis handle (e.g., choose location)%   'view'       - Camera viewpoint in deg. [azimuth elevation]%                  'back'|'b'=[  0 30]; 'front'|'f'=[180 30] %                  'left'|'l'=[-90 30]; 'right'|'r'=[ 90 30];%                  'frontleft'|'bl','backright'|'br', etc.,%                  'top'=[0 90]   {default [143 18]}%   'orilocs'    - [channel structure or channel file name] Use original %                  channel locations instead of the one extrapolated from %                  spherical locations.%   'maplimits'  - 'absmax' -> make limits +/- the absolute-max%                  'maxmin' -> scale to data range%                   [min,max] -> user-definined values%                   {default = 'absmax'; red +, blue -, green 0}%   'lights'     - (3,N) matrix whose rows give x,y,z pos. of %                   N lights {default: 4 lights at corners}%   'lighting'   - 'off' = show wire frame {default 'on'} %   'colormap'   -  3-column colormap matrix {default jet(64)}%   'verbose'    - 'off' -> no msgs, no rotate3d {default 'on'}%% Note: if an error is generated, headplot may close the current figure%% Authors: Arnaud Delorme, Colin Humphries, Scott Makeig, SCCN/INC/UCSD, %          La Jolla, 1998-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (C) Arnaud Delorme, Colin Humphries and Scott Makeig, %               CNL / Salk Institute, Feb. 1998%% Spherical spline method: Perrin et al. (1989) Electroenceph clin Neurophys%% This program is free software; you can redistribute it and/or modify% it under the terms of the GNU General Public License as published by% the Free Software Foundation; either version 2 of the License, or% (at your option) any later version.%% This program is distributed in the hope that it will be useful,% but WITHOUT ANY WARRANTY; without even the implied warranty of% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the% GNU General Public License for more details.%% You should have received a copy of the GNU General Public License% along with this program; if not, write to the Free Software% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA% $Log: headplot.m,v $% Revision 1.46  2004/07/26 21:05:22  arno% remove index1%% Revision 1.45  2004/07/26 21:04:32  arno% remove tri2%% Revision 1.44  2004/07/26 21:03:51  arno% remove mheadtri2%% Revision 1.43  2004/07/26 18:59:37  arno% nothing%% Revision 1.42  2004/07/09 16:10:04  arno% debug% cbar%% Revision 1.41  2004/07/01 22:17:37  arno% rename mhead files%% Revision 1.40  2004/07/01 22:12:35  arno% change default mesh%% Revision 1.39  2004/07/01 22:10:58  arno% using julie's head%% Revision 1.5  2004/07/01 22:10:19  arno% renormalize%% Revision 1.4  2004/07/01 18:03:24  arno% fixing coordinate problem for 32 electrodes%% Revision 1.3  2004/06/04 20:40:57  arno% default mesh problem%% Revision 1.2  2004/06/01 17:12:42  arno% mhead.mat file%% Revision 1.1  2004/05/12 02:12:25  arno% Initial revision%% Revision 1.34  2004/05/11 20:55:58  arno% same%% Revision 1.33  2004/05/10 17:11:02  arno% new decoding of arguments%% Revision 1.32  2004/03/25 23:09:29  arno% adding mesh tag to head mesh%% Revision 1.31  2004/03/25 19:43:13  arno% allowing to read custom mesh, fixed color bug%% Revision 1.30  2004/02/24 17:18:33  arno% using readlocs to read file%% Revision 1.29  2004/02/24 16:08:41  arno% removing spherical coords%% Revision 1.28  2004/02/24 15:39:03  arno% header msg%% Revision 1.27  2004/02/09 19:39:53  scott% returning to part-head view%% Revision 1.26  2004/02/08 16:32:46  scott% same%% Revision 1.25  2004/02/08 16:31:41  scott% trying newupper.mat again for 252 channels%% Revision 1.24  2004/02/08 15:31:36  scott% try to plot whole head%% Revision 1.23  2003/12/17 23:02:42  scott% remove output%% Revision 1.22  2003/12/17 23:00:24  scott% return Wout%% Revision 1.21  2003/12/17 22:58:11  scott% output TRI1%% Revision 1.20  2003/12/17 22:53:25  scott% add W output%% Revision 1.19  2003/12/17 01:04:24  arno% process empty coordinates%% Revision 1.18  2003/12/05 18:10:20  arno% loading files differently for windows%% Revision 1.17  2003/08/02 00:24:10  scott% nothing%% Revision 1.16  2002/11/26 19:42:24  arno% /2 to sqrt in extentricity calculation (thanks to Tyler Lorig)%% Revision 1.15  2002/11/19 20:08:28  arno% allowing ascii and binary read of mhead%% Revision 1.14  2002/11/19 19:45:09  arno% back to original%% Revision 1.13  2002/11/19 19:34:00  arno% mhead.dat -> mhead%% Revision 1.12  2002/11/19 19:30:37  arno% mhead -> mhead.dat%% Revision 1.11  2002/11/19 19:29:59  arno% mhead.mat -> mhead for windows compatibility%% Revision 1.10  2002/10/23 19:21:24  arno% fixing division error%% Revision 1.9  2002/10/23 19:01:51  arno% nothing%% Revision 1.8  2002/10/23 17:19:10  arno% cleaning up, removing ls for windows%% Revision 1.7  2002/10/23 17:06:26  arno% saving syntax change for windows%% Revision 1.6  2002/10/23 16:52:23  arno% testing%% Revision 1.5  2002/08/27 00:35:39  arno% closing current figure%% Revision 1.4  2002/08/14 16:48:54  arno% remove ICADIR%% Revision 1.3  2002/07/25 18:24:08  arno% debugging%% Revision 1.2  2002/04/17 20:56:14  arno% changing XYZ coordinate transformation for eloc structure%% Revision 1.1  2002/04/05 17:36:45  jorn% Initial revision%% 12-12-98 changed electrode label lines to MarkerColor -sm% 12-12-98 added colorbar option -sm (still graphically marred by tan rect.)% 12-13-98 implemented colorbar option using enhanced cbar -sm % 12-13-98 implemented 'setup' comment option -sm % 03-20-00 added cartesian electrode locations option -sm% 07-14-00 fixed line in calgx() -sm from -ch% 03-23-01 documented 'cartesian' locfile option -sm% 01-25-02 reformated help & license, added links -ad % 03-21-02 added readlocs and the use of eloc input structure -ad function [] = headplot(values, arg1, varargin)if nargin < 1    help headplot    returnend%%%%%%%%%%%%%%%%%%%%%%%%%% Set Defaults %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%icadefs   % load definitionsset(gca,'Color',BACKCOLOR);DEFAULT_MESH = ['mheadnew.mat'];      % upper head model file (987K)%DEFAULT_MESH  = '/home/arno/matlab/juliehiresmesh.mat';%DEFAULT_MESH  = ['/home/scott/matlab/old' '/newupper.mat'];                                  % whole head model file (183K)DEFAULT_LIGHTS = [-125  125  80; ...                  125  125  80; ...                  125 -125 125; ...                  -125 -125 125];    % default lights at four cornersHeadCenter = [0 0 30];FaceColor  = [.8 .55 .35]*1.1; % ~= ruddy Caucasian - pick your complexion!MAX_ELECTRODES = 1024;ElectDFac  = 1.06;  % plot electrode marker dots out from head surfaceNamesDFac  = 1.05;  % plot electrode names/numbers out from markersNamesColor = 'k'; % 'r';NamesSize  =  10;   % FontSize for electrode namesMarkerColor= 'k';sqaxis     = 1;     % if non-zero, make head proportions anatomicaltitle_font = 18;if isstr(values)    values   = lower(values);    if strcmp(values,'setup')        %%%%%%%%%%%%%%%%%%%% Perform splining file setup %%%%%%%%%%%%%%%%%%%%%%%%%%%%%    if nargin < 3        help headplot;        return;    end;    eloc_file = arg1;    spline_file = varargin{1};            g = finputcheck(varargin(2:end), { 'orilocs'   'string'  { 'on' 'off' }  'off';                                       'meshfile'  'string'  []              DEFAULT_MESH;                                       'comment'   'string'  []              '' });    if isstr(g),         clear g;         g.comment   = varargin{2};         g.orilocs   = 'off';        g.meshfile  = DEFAULT_MESH;    end;        %%%%%%%%%%%%%%%%%%%%%%%%%%%    % Open electrode file    %%%%%%%%%%%%%%%%%%%%%%%%%%%    [eloc_file labels Th Rd ind] = readlocs(eloc_file);    fprintf('Headplot: using existing XYZ coordinates\n');    %for index = 1:length(eloc_file)    %    eloc_file(index).radius     = eloc_file(index).radius*1.4;    %    eloc_file(index).sph_radius = 1;    %end;    %eloc_file = convertlocs(eloc_file, 'topo2all');    tmpX = { eloc_file.X };    tmpY = { eloc_file.Y };    tmpZ = { eloc_file.Z };    indices = find(~cellfun('isempty', tmpX));    ElectrodeNames = strvcat({ eloc_file.labels });    ElectrodeNames = ElectrodeNames(indices,:);    Xe = cell2mat( tmpX(indices) )';    Ye = cell2mat( tmpY(indices) )';    Ze = cell2mat( tmpZ(indices) )';    dists = sqrt(Xe.^2+Ye.^2+Ze.^2);    Xe = Xe./dists;    Ye = Ye./dists;    Ze = Ze./dists;    newcoords = [ Ye Xe Ze ];    newcoords = transformcoords( [ Xe Ye Ze ], [0 -pi/16 0], 100, [6 0 46]);    % original center was [6 0 16] but the center of the sphere is [0 0 30]     % which compensate (see variable Headcenter)    %newcoords = transformcoords( [ Xe Ye Ze ], [0 0 -pi/6]);    Xe = newcoords(:,1);    Ye = newcoords(:,2);    Ze = newcoords(:,3);    dists = sqrt(Xe.^2+Ye.^2+Ze.^2);    Xe = Xe./dists;    Ye = Ye./dists;    Ze = Ze./dists;    Xetmp = Xe;    Xe = -Ye;    Ye = Xetmp;    Xe = Xe(:);    Ye = Ye(:);    Ze = Ze(:);    %plotchans3d([ Xe Ye Ze], cellstr(ElectrodeNames)); return;        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    % Calculate g(x) for electrodes     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    fprintf('Setting up splining matrix.\n');    enum = length(Xe);    onemat = ones(enum,1);    G = zeros(enum,enum);    for i = 1:enum        ei = onemat-sqrt((Xe(i)*onemat-Xe).^2 + (Ye(i)*onemat-Ye).^2 + ...                         (Ze(i)*onemat-Ze).^2); % default was /2 and no sqrt        gx = zeros(1,enum);        for j = 1:enum            gx(j) = calcgx(ei(j));        end        G(i,:) = gx;    end    fprintf('Calculating splining matrix...\n')    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    % Open mesh file - contains POS and index1    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    if ~exist(g.meshfile)       error(sprintf('headplot(): mesh file "%s" not found\n',g.meshfile));    end    try, load(g.meshfile,'-mat');    catch,        POS  = load('mheadnewpos.txt', '-ascii');        TRI1 = load('mheadnewtri1.txt', '-ascii'); % upper head        %try, TRI2 = load('mheadnewtri2.txt', '-ascii'); catch, end; % lower head        %index1 = load('mheadnewindex1.txt', '-ascii');        center = load('mheadnewcenter.txt', '-ascii');    end;    if exist('index1') ~= 1, index1 = sort(unique(TRI1(:))); end;    if exist('TRI2')   ~= 1, TRI2 = []; end;    if exist('NORM')   ~= 1, NORM = []; end;    if exist('TRI1')   ~= 1, error('Variable ''TRI1'' not defined in mesh file'); end;    if exist('POS')    ~= 1, error('Variable ''POS'' not defined in mesh file'); end;    if exist('center') ~= 1, center = [0 0 0]; disp('Using [0 0 0] for center of head mesh'); end;        fprintf('Loaded mesh file %s\n',g.meshfile);    newPOS = POS(index1,:);        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    % Project head vertices onto unit sphere    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    nPOS = newPOS-ones(size(newPOS,1),1)*HeadCenter;    spherePOS = sqrt(ones./(sum((nPOS.*nPOS)')))'*ones(1,3).*nPOS;    x = spherePOS(:,1);    y = spherePOS(:,2);    z = spherePOS(:,3);        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    % Calculate new electrode positions

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?