-
Notifications
You must be signed in to change notification settings - Fork 197
dwifslpreproc: incorrect pe_table fed to applytopup #3122
Description
When using dwifslpreproc with a simple pair + dwi combo, I noticed that applytopup after topup is not correctly applying the field. The distortions are made worse instead of less and the resulting brain mask suffers as a result from that.
Looking into this, I noticed that (NOTE: the issue turned out not to be pe_table vs pe_eddy, but mrinfo vs mrconvert with strides).mrinfo -export_pe_table produces a txt file that has the phase encoding direction flipped as opposed to what mrinfo -export_pe_eddy produces. Since applytopup is using the txt file from mrinfo -export_pe_table, it appears to apply the opposite correction. Subsequent eddy on the other hand is using the txt file from mrinfo -export_pe_eddy, so it seems to apply the field correctly.
With dwi.mif containing a single PE direction:
mrinfo dwi.mif -export_pe_table pe_table.txt -export_pe_eddy pe_eddy.txt pe_eddy_idx.txt -force
cat pe_eddy.txt
produces
0 1 0 0.0321
whereas
head -n 1 pe_table.txt
produces
0 -1 0 0.0321
The cause seems to be that -export_pe_eddy boils down to save(transform_for_nifti_write(PE, header), path), which includes
mrtrix3/core/metadata/phase_encoding.cpp
Lines 262 to 283 in 2e4cb20
| scheme_type transform_for_nifti_write(const scheme_type& pe_scheme, const Header& H) { | |
| if (pe_scheme.rows() == 0) | |
| return pe_scheme; | |
| Axes::Shuffle shuffle = File::NIfTI::axes_on_write(H); | |
| if (shuffle.is_identity()) { | |
| INFO("No transformation of phase encoding data required for export to file:" | |
| " output image will be RAS"); | |
| return pe_scheme; | |
| } | |
| scheme_type result(pe_scheme.rows(), pe_scheme.cols()); | |
| for (ssize_t row = 0; row != pe_scheme.rows(); ++row) { | |
| Eigen::VectorXd new_line = pe_scheme.row(row); | |
| for (ssize_t axis = 0; axis != 3; ++axis) | |
| new_line[axis] = | |
| pe_scheme(row, shuffle.permutations[axis]) != 0.0 && shuffle.flips[axis] ? | |
| -pe_scheme(row, shuffle.permutations[axis]) : | |
| pe_scheme(row, shuffle.permutations[axis]); | |
| result.row(row) = new_line; | |
| } | |
| INFO("Phase encoding data transformed to match NIfTI / MGH image export prior to writing to file"); | |
| return result; | |
| } |
-export_pe_table boils down to save(PE, path), missing the nifti-specific logic.