-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateGrids.m
130 lines (100 loc) · 2.75 KB
/
createGrids.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
function createGrids(target)
% function createGrids(target)
%
% This function creates a set of regular grid images to help visualise
% geometric transformations estimated by image registration algorithms.
%
%
% INPUT:
%
% 1. target - a string specifying the file name of a NIfTI file; the voxel
% space of this file will be used for the output grid volumes.
%
% IMPORTANT: the file name should not included the suffix.
%
%
% OUTPUT: the output will be a set of three volumes in the Data/grids
% folder
%
%
% Requirements: the following two softwares are required.
%
% 1. DTI-TK
%
% 2. FSL
%
%
% Author: Gary Hui Zhang ([email protected])
%
%
%% check an input is provided
if (nargin < 1)
fprintf('Please provide the name of a target NIfTI volume\n');
fprintf('Include full path but not the NIfTI suffix\n\n');
return;
end
%% set up DTI-TK
setupDTITK();
%% set up FSL
setupFSL();
%% change to the demo's Data folder and set up the data path
% remember the current directory
originalDIR = pwd();
% change to the Data folder
toDataDIR();
% change to the grids folder
cd('grids');
%% create the grid volumes
% the target volume for the grid volumes with full path
%
% note that unlike FSL, DTI-TK requires the suffix of the NIfTI files to
% be included
%
targetImageFilename = fullfile(originalDIR, [target '.nii.gz']);
% set up the command string to create the grid volumes
cmd = ['SVtool -target ' targetImageFilename ' -grid'];
% print out the command string
disp(cmd);
% execute the command
unix(cmd);
%% match the NIfTI header info fully
%
% DTI-TK does not duplicate the target volume's full header; we use a FSL
% tool to fix this.
%
grids = {'gridx', 'gridy', 'gridz'};
for i=1:length(grids)
% set up the command string to duplicate header
cmd = ['fslcpgeom ' targetImageFilename ' ' grids{i}];
% print out the command string
disp(cmd);
% execute the command
unix(cmd);
end
%% rename the grid volumes
%
% rename the grid volumes to include the target name as the prefix.
%
% this bit will not rename the files but also move the files to the same
% folder as the target
for i=1:length(grids)
% set up the command string to renaming
cmd = ['mv ' grids{i} '.nii.gz ' fullfile(originalDIR, target) '-' grids{i} '.nii.gz'];
% print out the command string
disp(cmd);
% execute the command
unix(cmd);
end
% we now need to move them back to grids folder
for i=1:length(grids)
% set up the command string to moving
cmd = ['mv ' fullfile(originalDIR, target) '-' grids{i} '.nii.gz .'];
% print out the command string
disp(cmd);
% execute the command
unix(cmd);
end
%% when done, change back to the original working folder
cd(originalDIR);
%% end of function
end