-
Notifications
You must be signed in to change notification settings - Fork 2
/
ROI_parcellation.m
102 lines (86 loc) · 2.82 KB
/
ROI_parcellation.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
function ROI_parcellation(PWD,ROI,SUB_LIST,MAX_CL_NUM,POOLSIZE,METHOD,LEFT,RIGHT)
% ROI parcellation
% addpath('/DATA/249/bhe/Atpp/ATPP/NIfTI_20130306');
SUB = textread(SUB_LIST,'%s');
method = METHOD;
N = MAX_CL_NUM-1;
% modify temporary dir
temp_dir=tempname();
mkdir(temp_dir);
if exist('parcluster')
pc=parcluster('local');
pc.JobStorageLocation=temp_dir;
else
sched=findResource('scheduler','type','local');
sched.DataLocation=temp_dir;
end
% open pool
if exist('parpool')
p=parpool('local',POOLSIZE);
else
matlabpool('local',POOLSIZE);
end
parfor i = 1:length(SUB);
if LEFT == 1
outdir_L = strcat(PWD,'/',SUB{i},'/',SUB{i},'_',ROI,'_L','_',method);
if ~exist(outdir_L,'dir') mkdir(outdir_L); end
data = load(strcat(PWD,'/',SUB{i},'/',SUB{i},'_',ROI,'_L_matrix/connection_matrix.mat'));
coordinates = data.xyz;
matrix = data.matrix;
panduan = any(matrix');
coordinates = coordinates(panduan,:);
matrix = matrix(panduan,:);
matrix1 = matrix*matrix';
matrix1 = matrix1-diag(diag(matrix1));
nii = load_untouch_nii(strcat(PWD,'/',SUB{i},'/',SUB{i},'_',ROI,'_L_DTI.nii.gz'));
image_f=nii.img;
for k=1:N
filename=strcat(outdir_L,'/',ROI,'_L_',num2str(k+1),'.nii.gz');
if ~exist(filename,'file')
display(strcat(SUB{i},'_',ROI,'_L_',num2str(k+1),' processing...'));
index=sc3(k+1,matrix1);
image_f(:,:,:)=0;
for j = 1:length(coordinates)
image_f(coordinates(j,1)+1,coordinates(j,2)+1,coordinates(j,3)+1)=index(j);
end
nii.img=image_f;
save_untouch_nii(nii,filename);
end
end
display(strcat(SUB{i},'_',ROI,'_L',' Done!'));
end
if RIGHT == 1
outdir_R = strcat(PWD,'/',SUB{i},'/',SUB{i},'_',ROI,'_R','_',method);
if ~exist(outdir_R,'dir') mkdir(outdir_R); end
data = load(strcat(PWD,'/',SUB{i},'/',SUB{i},'_',ROI,'_R_matrix/connection_matrix.mat'));
coordinates = data.xyz;
matrix = data.matrix;
panduan = any(matrix');
coordinates = coordinates(panduan,:);
matrix = matrix(panduan,:);
matrix1 = matrix*matrix';
matrix1 = matrix1-diag(diag(matrix1));
nii = load_untouch_nii(strcat(PWD,'/',SUB{i},'/',SUB{i},'_',ROI,'_R_DTI.nii.gz'));
image_f=nii.img;
for k=1:N
filename=strcat(outdir_R,'/',ROI,'_R_',num2str(k+1),'.nii.gz');
if ~exist(filename,'file')
display(strcat(SUB{i},'_',ROI,'_R_',num2str(k+1),' processing...'));
index=sc3(k+1,matrix1);
image_f(:,:,:)=0;
for j = 1:length(coordinates)
image_f(coordinates(j,1)+1,coordinates(j,2)+1,coordinates(j,3)+1)=index(j);
end
nii.img=image_f;
save_untouch_nii(nii,filename);
end
end
end
display(strcat(SUB{i},'_',ROI,'_R',' Done!'));
end
% close pool
if exist('parpool')
delete(p);
else
matlabpool close;
end