-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloreta_importcomp.m
106 lines (97 loc) · 4.25 KB
/
loreta_importcomp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
% loreta_importcomp() - Overlay activation on MNI normalized brain.
%
% Usage:
% >> mri = loreta_importcomp( mrifile, actfile, 'key', 'val', ... );
%
% Inputs:
% mri - mri structure normalized to MNI brain. Supposed to contain
% a field anatomy and a field transform.
% act - activation value, one per voxel
%
% optional inputs:
% 'smooth' - [integer] optional 3-D smoothing (in MNI voxels (mm)).
% 'mrigamma' - [float] mri gamma factor (alter contrast). 1 does not
% change contrast. < 1 increases contrast; > 1 decreases
% contrast.
% 'actgamma' - [float] activity gamma factor (alter contrast). 1 does not
% change contrast. < 1 increases contrast; > 1 decreases
% contrast.
% 'actfactor' - [float] activity factor from 0 to 1. Default is 0.4.
% A factor too high might cause the voxel color to go over
% the color limits.
% 'filelocs' - [string] location file for LORETA voxels in MNI space.
% This is contained in the file 'LORETAtalairach.xyz' from
% the LORETA distribution. This is also distributed with
% this plugin.
%
% Outputs:
% mri - mri structure with a new field "anatomycol" containing
% true color voxel values.
%
% Example:
% [anat act mri] = loreta_importcomp( [ '/data/common/matlab/eeglab/plugins/dipfit2.0/' ...
% 'standard_BEM/standard_mri.mat' ], 'LORETAloc.lor3');
% plotmri(anat, act, 'transform', mri.transform);
%
% Author: Arnaud Delorme, SCCN, INC, UCSD, 2005
% Copyright (C) Arnaud Delorme, SCCN, INC, UCSD, 2005 [email protected]
%
% 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
function [mri, act, mristruct] = loreta_importcomp(mrifile, fileact, varargin)
if nargin < 2
help loreta_importcomp
return;
end;
g = finputcheck(varargin, { 'smooth' 'integer' [0 Inf] 0;
'actgamma' 'real' [0 Inf] 1;
'mrigamma' 'real' [0 Inf] 1;
'filelocs' 'string' [] 'LORETAtalairach.xyz';
'actfactor' 'real' [0 Inf] 0.4 });
if isstr(g), error(g); end;
% get locations
% -------------
fid = fopen(g.filelocs, 'r'); % should be at the same location as
% this file
if fid == -1, error([ 'Cannot find or open ''' g.filelocs ''' file' ]); end;
nlines = fscanf(fid, '%d',1 ); % should be equal to 2394
locations = fscanf(fid, '%d', [2394*3]);
locations = reshape(locations, [3 2394])';
fclose(fid);
% get values
% ----------
%fid = fopen('LORETAloc.lor3', 'r')
fid = fopen(fileact, 'r');
if fid == -1, error([ 'Cannot find or open ''' fileact ''' file' ]); end;
Xact = fread(fid, 2394, 'float');
Yact = fread(fid, 2394, 'float');
Zact = fread(fid, 2394, 'float');
activations = sqrt(Xact.^2 + Yact.^2 + Zact.^2);
fclose(fid);
% read MRI if necessary
% ---------------------
if isstr(mrifile)
try,
mrifile = load('-mat', mrifile);
mrifile = mrifile.mri;
catch,
warning backtrace off;
mrifile = read_fcdc_mri(mrifile);
warning backtrace on;
end;
end;
% colorize MRI
% ------------
[mri act mristruct] = colorizemri( mrifile, locations, activations, 'voxsize', 7, 'smooth', g.smooth, ...
'actfactor', g.actfactor, 'actgamma', g.actgamma, 'mrigamma', g.mrigamma);