source: misclib/fmri_corr.m @ 64

Last change on this file since 64 was 53, checked in by tjniskan, 11 years ago
  • Fixed a bug in an2_readfid.m that in some cases didn't calculate

the array length in procpar correctly. Also changed the handling of
array parameter in an2_readprocpar.m.

  • Fixed a bug in an2_rot3d.m
  • Fixed bugs here and there
  • Added some incomplete code for upcoming new features.

M misclib/nifti4dto3d.m
M misclib/fmri_corr.m
M an2_rot3d.m
M an2_revision.m
M an2_readprocpar.m
M an2_data_read.m
M aedes.m
M an2_res2table.m
M an2_copy_roi.m
M an2_roi_copy_gui.m
M an2_readfid.m
M an2_saveres.m
M an2_write_nifti.m

File size: 1.7 KB
Line 
1function corrmap = fmri_corr(data,seed)
2
3corrmap = [];
4
5if ischar(data)
6  data=an2_data_read(data);
7  data = data.FTDATA;
8end
9
10seed_struct = l_Roi2seed(data,seed);
11
12
13
14% Calculate Pearson correlation coefficients -------------
15
16data_sz = ones(1,4);
17data_sz(1:ndims(data)) = size(data);
18
19for kk = 1:length(seed_struct)
20 
21  % Allocate space for ccc
22  ccc = zeros(data_sz(1:3));
23 
24  T = length(seed_struct(kk).data);
25  std_seed = std(seed_struct(kk).data,1);
26  norm_seed = seed_struct(kk).data-mean(seed_struct(kk).data);
27  seed_plane = reshape(reshape(repmat(norm_seed,...
28        [data_sz(1),data_sz(2)]),data_sz(1)*T,[]).',...
29        data_sz(1),data_sz(2),[]);
30 
31  % Loop over in-plane slices
32  for ii=1:data_sz(3)
33        tmp_data = double(squeeze(data(:,:,ii,:)));
34       
35        std_data = std(tmp_data,1,3);
36       
37        ccc(:,:,ii) = ((1/T)*sum(seed_plane.*tmp_data,3))./(std_data.*std_seed);
38  end
39 
40  % Make sure that there are no Infs or nans ...
41  ccc(find(isnan(ccc))) = 0;
42  ccc(find(isinf(ccc))) = 0;
43 
44  % Fisher's z-transform to make values normally distributed
45  zf = ccc;
46  zf = 0.5*log((1+ccc)./(1-ccc));
47 
48  % Calculate Z-scores
49  zscore = zf./(1/sqrt(T-3));
50 
51  % Construct output structure
52  corrmap(kk).ccc = ccc;
53  corrmap(kk).zf = zf;
54  corrmap(kk).zscore = zscore;
55  corrmap(kk).label = seed_struct(kk).label;
56end
57
58% Subfunctions -----------------------------------
59function seed_struct = l_Roi2seed(data,ROI)
60
61seed_struct = [];
62
63if isstruct(ROI)
64  for ii=1:length(ROI)
65        ind = repmat(ROI(ii).voxels{1}(:,:,:,1),[1 1 1 size(data,4)]);
66        seed_struct(ii).data = mean(reshape(double(data(ind)),[],size(data,4)));
67        seed_struct(ii).label = ROI(ii).label;
68  end
69else
70  tmp = ROI(:).';
71  seed_struct(1).data = double(tmp);
72  seed_struct(1).label = 'custom seed';
73end
74
75
76
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008