-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlistair_code.txt
executable file
·70 lines (57 loc) · 2.37 KB
/
Alistair_code.txt
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
% function [TempFinalIndex, Tempstrings] = regions2templateindex(parcniifile, tempniifile, tempLabels)
%regions2templateindex - For each parcellation region, find their best
%corresponding match within a target template image (i.e. Yeo 2011 Functional Clusters, AAL)
%[INPUT]:
%parcniifile = filename of the source parcellation template
%temppniifile = filename of the target template
%!!! Both files must be in nii format and in the same space
%tempLabels = strings corresponding to the integers within the target image
%[OUTPUT]:
%TempFinalIndex = Corresponding integer for each source region's best
%match in the template image
%TempFinalStrings = Corresponding label for the source region's best
%match in the template image
%Alistair Perry(QIMR), 2017.
parcniifile = 'L:/Lab_JamesR/jamesPa/atlas_generation/HCP_atlases/QIMR_512.nii';
tempniifile = 'L:/Lab_JamesR/jamesPa/atlas_generation/HCP_atlases/AAL2_120.nii';
names = load('L:/Lab_JamesR/jamesPa/atlas_generation/HCP_atlases_node_details/region_names_AAL2_120.mat');
tempLabels = names.region_names;
% [parcdata] = load_untouch_nii(parcniifile);
% numparcsints = max(max(max(parcdata.img)));
% [tempdata] = load_untouch_nii(tempniifile);
% numtempints = max(max(max(tempdata.img)));
hdr = spm_vol(parcniifile);
parcdata.img = spm_read_vols(hdr);
numparcsints = max(parcdata.img(:));
hdr = spm_vol(tempniifile);
tempdata.img = spm_read_vols(hdr);
numtempints = max(tempdata.img(:));
for i = 1:numparcsints
findparci = find(parcdata.img==i);
tempmatch = tempdata.img(findparci);
[tempmatches, ~, ~] = unique(tempmatch);
tempmatches(tempmatches==0)=[];
for j = 1:length(tempmatches);
tempmatches(j,2) = length(find(tempmatch==tempmatches(j,1)));
end
if isempty(tempmatches)
TempFinalIndex(i,1) = 0;
else
tempmatches = sortrows(tempmatches,2);
TempFinalIndex(i,1) = tempmatches(j,1);
end
end
Tempstrings = cell(numparcsints,1);
for i = 1:numtempints
[Tempmatch,~] = find(TempFinalIndex==i);
for j = 1:length(Tempmatch)
Tempstrings(Tempmatch(j,1),1) = {[tempLabels{i,1} '_' int2str(j)]};
end
end
% SAVE TO JSON FILE
JSONFILE_name= 'QIMR_512.json';
fid=fopen(JSONFILE_name,'w');
encodedJSON = jsonencode(AALstrings);
fprintf(fid, encodedJSON);
fclose('all');
% end