forked from justingardner/gru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplyScalingFactor.m
31 lines (24 loc) · 965 Bytes
/
applyScalingFactor.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
function applyScalingFactor(baseImg,sFacs)
%rename old file with extension preGradCoil
moveoldfilenametothis = setext(sprintf('%s_preGradCoil',stripext(baseImg)),'hdr');
%check if this function has been run in the past
if isfile(moveoldfilenametothis);
disp(sprintf('Pre gradient coil replacement header file found in this directory. You may have already scaled this image. Image not scaled.'));
return
end
sMat = diag(sFacs);
sMat = [[sMat; 0 0 0;] [0 0 0 1]'];
basehdr = setext(baseImg,'hdr');
[data hdr] = cbiReadNifti(basehdr);
newsform44 = sMat*hdr.sform44;
newqform44 = sMat*hdr.qform44;
newhdr = cbiSetNiftiSform(hdr,newsform44);
newhdr = cbiSetNiftiQform(hdr,newqform44);
%move the old header to have this extention
command = sprintf('!mv %s %s',baseImg,moveoldfilenametothis);
eval(command);
if isfile(moveoldfilenametothis)
newfilename = setext(sprintf('%s',stripext(baseImg)),'hdr');
cbiWriteNifti(newfilename,data,newhdr);
end
end