Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DWI metadata fixes for master #3011

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft

DWI metadata fixes for master #3011

wants to merge 8 commits into from

Conversation

Lestropie
Copy link
Member

Re-implementation of #2917.
Closes #2477.
Closes #2998.
Supersedes #2900.
Supersedes #2912.

As mentioned in #2917, these changes are all ultimately bug fixes, so should have been implemented on master from the outset. But because of the mass reformatting changes on dev, I had to transfer most of this changeset manually.

The tool over at https://github.com/Lestropie/DWI_metadata is now containerised, and currently configured to download and test this branch. It shows that with these changes, the only tests not passing are those that take sagittal DWIs from dcm2niix as input, as dcm2niix gets the polarity of its bvecs incorrect in those data.

This commit is a manual replication of the contents of #2917, but targeting 3.0.x.
Do not convert contents of text JSON file to integers / floats then convert back to strings for storage in a KeyValues instance; instead just use the string representation. This fixes an issue whereby if a JSON is generated from an image, but that image also retains the same metadata fields in its own header, and then the JSON contents are re-imported, the two values for floating-point metadata elements could differ due to floating-point imprecision, and this would lead to the field being reset to the value "variable".
@Lestropie Lestropie added the bug label Sep 20, 2024
@Lestropie Lestropie added this to the 3.0.5 updates milestone Sep 20, 2024
@Lestropie Lestropie requested a review from a team September 20, 2024 23:39
@Lestropie Lestropie self-assigned this Sep 20, 2024
@Lestropie Lestropie marked this pull request as draft September 22, 2024 01:03
Lestropie added a commit that referenced this pull request Sep 22, 2024
In order for a bvecs file to be properly read in, the information about how the image was transformed upon image load needs to be available. However if an attempt is made to perform such a read based on a Header that it has itself been constructed from an arbitrary ImageType, this information is lost. Therefore, reading from a bvecs file needs to be done using the Header class in which the corresponding NIfTI was originally opened.
In the process, some functionalities of the tracking of that transformation on image load have been made more explicit.
Also fixes some syntax errors relating to the manual back-porting of #2917 in #3011.
@Lestropie
Copy link
Member Author

Lestropie commented Sep 22, 2024

Encountered a trap here that simply checking metadata didn't catch, but shows up when testing all commands. Reading bvecs properly requires knowledge of the header transformation as stored on the filesystem, before MRtrix3 (possibly) does its internal transform realignment. However, if you construct an Image<> class instance, and then attempt to load the corresponding bvecs, then that Image<> class only knows the MRtrix3-interpreted transform, not what was stored on disk.

Prior to a6a4a87 (Edit: replaced with 2be257c), this compiled fine specifically because of a non-explicit templated Header copy constructor: one generates an Image<> from a Header, then from the Image<> implicitly produces a Header for DWI gradient table loading. But this would yield a NaN-filled gradient table since the bastardised Header would not have the transform realignment information. I have some recollection of prior discussions about whether generating a Header from an arbitrary ImageType should need to be explicit...

I decided against the option of integrating this internal realignment information into the ImageType class template. In particular this information does not to me make sense to necessitate explicit implementation in Adapter classes. Instead, this realignment information remains a part of the Header class, and commands that must find DWI gradient table information (possibly from the command-line) do so based on a Header class instance. It is nevertheless possible that a developer could erroneously do the Header -> Image<> -> Header process, and then bvecs import will fail. At least now it'll fail with NaNs everywhere rather than producing an erroneous result.

Lestropie added a commit that referenced this pull request Sep 22, 2024
In order for a bvecs file to be properly read in, the information about how the image was transformed upon image load needs to be available. However if an attempt is made to perform such a read based on a Header that it has itself been constructed from an arbitrary ImageType, this information is lost. Therefore, reading from a bvecs file needs to be done using the Header class in which the corresponding NIfTI was originally opened.
In the process, some functionalities of the tracking of that transformation on image load have been made more explicit.
Also fixes some syntax errors relating to the manual back-porting of #2917 in #3011.
In order for a bvecs file to be properly read in, the information about how the image was transformed upon image load needs to be available. However if an attempt is made to perform such a read based on a Header that it has itself been constructed from an arbitrary ImageType, this information is lost. Therefore, reading from a bvecs file needs to be done using the Header class in which the corresponding NIfTI was originally opened.
In the process, some functionalities of the tracking of that transformation on image load have been made more explicit.
Also fixes some syntax errors relating to the manual back-porting of #2917 in #3011.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mrconvert: fslgrad and RealignTransform: 0 DWI metadata fixes on master
1 participant