-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdp_node_mrtrix_dwigradcheck.m
executable file
·66 lines (47 loc) · 2.17 KB
/
dp_node_mrtrix_dwigradcheck.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
classdef dp_node_mrtrix_dwigradcheck < dp_node_mrtrix & dp_node_dmri
methods
function obj = dp_node_mrtrix_dwigradcheck()
end
function output = i2o(obj, input)
% this node will copy the dwi volume without doing anything
% about it, because we want to maintain the tight coupling
% with the xps and the dwi - thus, it is recommended that this
% node is only used in a temporary folder, ideally coupled
% with other preprocessing steps
% this is wasteful in terms of storage
output.dmri_fn = dp.new_fn(input.op, input.dmri_fn, '_gc');
output.bval_fn = dp.new_fn(input.op, input.dmri_fn, '_gc', '.bval');
output.bvec_fn = dp.new_fn(input.op, input.dmri_fn, '_gc', '.bvec');
output.xps_fn = mdm_xps_fn_from_nii_fn(output.dmri_fn);
output.tmp.bp = msf_tmp_path();
output.tmp.do_delete = 1;
end
function output = execute(obj, input, output)
% test the xps
xps = mdm_xps_load(input.xps_fn);
if (isfield(xps, 'b_delta')) && ...
(any((xps.b_delta <= 0.99) & (xps.b > 0)))
error('not defined for b-tensor encoding')
end
% prepare output
msf_mkdir(fileparts(output.bvec_fn));
msf_delete(output.bval_fn);
msf_delete(output.bvec_fn);
cmd = sprintf('dwigradcheck %s -fslgrad %s %s -export_grad_fsl %s %s', ...
input.dmri_fn, ...
input.bvec_fn, input.bval_fn, ....
output.bvec_fn, output.bval_fn);
obj.system(cmd);
% write an xps too
xps = mdm_xps_from_bval_bvec(output.bval_fn, output.bvec_fn);
mdm_xps_save(xps, output.xps_fn);
% copy the image data: load and save to create new dates
fid = fopen(input.dmri_fn, 'r');
data = fread(fid, inf, 'uint8');
fclose(fid);
fid = fopen(output.dmri_fn, 'w');
fwrite(fid, data, 'uint8');
fclose(fid);
end
end
end