-
Notifications
You must be signed in to change notification settings - Fork 2
/
ROI_calc_coord.m
72 lines (59 loc) · 1.82 KB
/
ROI_calc_coord.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
function ROI_calc_coord(WD,ROI,SUB_LIST,POOLSIZE,LEFT,RIGHT)
% Calculate coordinates of the voxels in the ROI in DTI space
SUB = textread(SUB_LIST,'%s');
% Parallel Computing Toolbox settings
% 2014a removed findResource, replaced by parcluster
% 2016b removed matlabpool, replaced by parpool
% 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
%**************add the code by hebin to judge the type of POOLSIZE*********************
if ischar(POOLSIZE)
POOLSIZE=str2num(POOLSIZE); % convert
end
%**************************************************************************************
% open pool
if exist('parpool')
p=parpool('local',POOLSIZE);
else
matlabpool('local',POOLSIZE);
end
parfor i = 1:length(SUB);
if LEFT == 1
roi_l = load_untouch_nii(strcat(WD,'/',SUB{i},'/',SUB{i},'_',ROI,'_L_DTI.nii.gz'));
[nxl,nyl,nzl] = size(roi_l.img);
fid_l = fopen(strcat(WD,'/',SUB{i},'/',SUB{i},'_',ROI,'_L_coord.txt'),'w');
for zl = 1:nzl;
[xl yl] = find(roi_l.img(:,:,zl) == 1);
for j = 1:numel(xl);
fprintf(fid_l,'%d %d %d\r\n',xl(j)-1,yl(j)-1,zl-1);
end
end
disp(strcat(SUB{i},'_L',' Done!'));
end
if RIGHT == 1
roi_r = load_untouch_nii(strcat(WD,'/',SUB{i},'/',SUB{i},'_',ROI,'_R_DTI.nii.gz'));
[nxr,nyr,nzr] = size(roi_r.img);
fid_r = fopen(strcat(WD,'/',SUB{i},'/',SUB{i},'_',ROI,'_R_coord.txt'),'w');
for zr = 1:nzr;
[xr yr] = find(roi_r.img(:,:,zr) == 1);
for j = 1:numel(xr);
fprintf(fid_r,'%d %d %d\r\n',xr(j)-1,yr(j)-1,zr-1);
end
end
disp(strcat(SUB{i},'_R',' Done!'));
end
end
% close pool
if exist('parpool')
delete(p);
else
matlabpool close;
end