Hi Jesper,
Many thanks for your previous message, it was very helpful.
I am getting there now, but seem to have a problem with applying the MC to the real and imaginary images.
My full code is attached to the bottom of this email, however the specific problem arises when correcting for motion after the distortion correction. I insert the magnitude (after DC) and specify -meanvol and that I would like the .mat files. I then use flirt to apply the same transform to the real and imaginary parts, also after the DC.
%motion correction (checking quality on magnitude)
!$FSLDIR/bin/mcflirt -meanvol -in m_DC_test.nii.gz -out m_DC_MC2.nii.gz -mats
%motion correct real and imag images
!$FSLDIR/bin/flirt -in re_DC -ref m_DC_MC2 -out re_mc_dc -applyxfm -init m_DC_MC2.nii.gz.mat -cost bbr
!$FSLDIR/bin/flirt -in im_DC -ref m_DC_MC2 -out im_mc_dc -applyxfm -init m_DC_MC2.nii.gz.mat -cost bbr
I am wondering whether I should perform the MC before the DC, but then thought the template would be distorted and therefore useless?
Any help would be much appreciated.
Many thanks
Lucy
===========================
!$FSLDIR/bin/fslmerge -t mAPPA mAP.nii.gz mPA.nii.gz
!$FSLDIR/bin/topup --imain=mAPPA --datain=topup_param.txt --config=b02b0.cnf --out=my_topup_results --fout=my_field --iout=uAPPA
%add MRE frequencies together
!$FSLDIR/bin/fslmerge -t M m20.nii.gz m30.nii.gz m40.nii.gz
!$FSLDIR/bin/fslmerge -t P p20.nii.gz p30.nii.gz p40.nii.gz
%test of distortion correction of plain magnitude data (not split)
!$FSLDIR/bin/applytopup --imain=M --inindex=1 --datain=topup_param.txt --topup=my_topup_results --method=jac --interp=spline --out=m_DC_test
!gunzip -f M.nii.gz
!gunzip -f P.nii.gz
m = load_untouch_nii('M.nii');
p = load_untouch_nii('P.nii');
p_img = double(p.img);
m_img = double(m.img);
cplx = m_img .* exp(1i.*p_img*2*pi/(4096*2));
re.img = real(cplx);
im.img = imag(cplx);
re.hdr.dime.datatype = 64;
im.hdr.dime.datatype = 64;
real = make_nii(re.img,[2.3 2.3 2.3], re.hdr.dime.datatype);
save_nii(real,'real.nii')
imag = make_nii(im.img,[2.3 2.3 2.3], im.hdr.dime.datatype);
save_nii(imag,'imag.nii')
!$FSLDIR/bin/fslswapdim real -x y z real2
!$FSLDIR/bin/fslswapdim imag -x y z imag2
%correction done here on real and imag.nii files (applytopup)
!$FSLDIR/bin/applytopup --imain=real2 --inindex=1 --datain=topup_param.txt --topup=my_topup_results --method=jac --interp=spline --out=re_DC
!$FSLDIR/bin/applytopup --imain=imag2 --inindex=1 --datain=topup_param.txt --topup=my_topup_results --method=jac --interp=spline --out=im_DC
%motion correction (checking quality on magnitude)
!$FSLDIR/bin/mcflirt -meanvol -in m_DC_test.nii.gz -out m_DC_MC2.nii.gz -mats
%motion correct real and imag images
!$FSLDIR/bin/flirt -in re_DC -ref m_DC_MC2 -out re_mc_dc -applyxfm -init m_DC_MC2.nii.gz.mat -cost bbr
!$FSLDIR/bin/flirt -in im_DC -ref m_DC_MC2 -out im_mc_dc -applyxfm -init m_DC_MC2.nii.gz.mat -cost bbr
re = load_untouch_nii('re_mc_dc.nii');
im = load_untouch_nii('im_mc_dc.nii');
im_img = double(im.img);
re_img = double(re.img);
DATA_ma = abs(re.img + 1i*im.img);
DATA_ph = angle(re.img + 1i*im.img)/pi*4096;
F_mag = make_nii(DATA_ma);
save_nii(F_mag,'f_mag.nii')
F_phs = make_nii(DATA_ph);
save_nii(F_phs,'f_phase.nii')
|