-
Notifications
You must be signed in to change notification settings - Fork 8
/
rest_TwoGroupCorr.m
executable file
·88 lines (79 loc) · 3.46 KB
/
rest_TwoGroupCorr.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
function rest_TwoGroupCorr(Group1Dir,Group2Dir,flag,outdir)
% FORMAT rest_TwoGroupCorr(Group1Dir,Group2Dir)
% Input:
% Group1Dir - directory of the first group
% Group2Dir - directory of the the second group
% flag - identify 'temporal' of 'spatial'
% outdir - directory of output
% Output for spatial:
% rGroup.img - image with Pearson's Correlation Coefficient
% pGroup.img - image with significance of Pearson's Correlation Coefficient
% Output for temporal:
% RandP.txt - r and p value for every point
%__________________________________________________________________________
% Written by YAN Chao-Gan 090302.
% State Key Laboratory of Cognitive Neuroscience and Learning, Beijing Normal University, China, 100875
%__________________________________________________________________________
% Revised by Dong Zhang-Ye, 100530. Add the function to calculate spatial correlation of two single image.
if strcmp(flag,'temporal')
temcorr(Group1Dir,Group2Dir,outdir);
else
spcorr(Group1Dir,Group2Dir,outdir);
end
function spcorr(Group1Dir,Group2Dir,outdir)
olddir=pwd;
if isdir(Group1Dir)&&isdir(Group2Dir)
[Group1Series, VoxelSize, ImgFileList, Header,nVolumn] =rest_to4d(Group1Dir);
[Group2ConSeries, VoxelSize, ImgFileList, Header,nVolumn] =rest_to4d(Group2Dir);
else
[Group1Series, VoxelSize, Header] =rest_readfile(Group1Dir); %dong 100530
[Group2ConSeries, VoxelSize, Header] =rest_readfile(Group2Dir);
ImgFileList=1;
nVolumn=1; %YAN Chao-Gan, 130423
end
cd(olddir);
rGroup=zeros(size(Group1Series,1),size(Group1Series,2),size(Group1Series,3));
pGroup=zeros(size(Group1Series,1),size(Group1Series,2),size(Group1Series,3));
rest_waitbar;
%for i=1:nVolumn
%[r p]=corrcoef(squeeze(Group1Series(i,:,:,:)),squeeze(Group2ConSeries(i,:,:,:)));
for i=1:nVolumn
rest_waitbar(i/size(Group1Series,1),'Computing','Computing','Parent');
[r p]=corrcoef(squeeze(Group1Series(:,:,:,i)),squeeze(Group2ConSeries(:,:,:,i)));
rGroup(i)=r(1,2);
pGroup(i)=p(1,2);
end
rGroup(isnan(rGroup))=0;
pGroup(isnan(pGroup))=1;
fid=fopen([outdir,filesep,'R_P.txt'],'w');
if(fid>0)
fprintf(fid,'ID\tR\t\tP\n');
for i=1:size(ImgFileList,1)
fprintf(fid,'%d\t%f\t%f\n',i,rGroup(i),pGroup(i));
end
end
function temcorr(Group1Dir,Group2Dir,outdir)
olddir=pwd;
[Group1Series, VoxelSize, ImgFileList, Header,nVolumn] =rest_to4d(Group1Dir);
[Group2ConSeries, VoxelSize, ImgFileList, Header,nVolumn] =rest_to4d(Group2Dir);
cd(olddir);
rGroup=zeros(size(Group1Series,1),size(Group1Series,2),size(Group1Series,3));
pGroup=zeros(size(Group1Series,1),size(Group1Series,2),size(Group1Series,3));
rest_waitbar;
%for i=1:nVolumn
%[r p]=corrcoef(squeeze(Group1Series(i,:,:,:)),squeeze(Group2ConSeries(i,:,:,:)));
for i=1:size(Group1Series,1) %YAN Chao-Gan, 20130423. ZHANG Han found this bug.
rest_waitbar(i/size(Group1Series,1),'Computing','Computing','Parent');
for j=1:size(Group1Series,2)
for k=1:size(Group1Series,3)
[r p]=corrcoef(squeeze(Group1Series(i,j,k,:)),squeeze(Group2ConSeries(i,j,k,:)));
rGroup(i,j,k)=r(1,2);
pGroup(i,j,k)=p(1,2);
end
end
end
rGroup(isnan(rGroup))=0;
pGroup(isnan(pGroup))=1;
rest_WriteNiftiImage(rGroup,Header,[outdir,filesep,'rGroup.img']);
rest_WriteNiftiImage(pGroup,Header,[outdir,filesep,'pGroup.img']);