Skip to content

dwifslpreproc & mrcat: Strides fix#2806

Merged
Lestropie merged 3 commits intomasterfrom
dwifslpreproc_mrcat_strides_fix
Jul 24, 2025
Merged

dwifslpreproc & mrcat: Strides fix#2806
Lestropie merged 3 commits intomasterfrom
dwifslpreproc_mrcat_strides_fix

Conversation

@Lestropie
Copy link
Member

Traced issue back to here, which ties all the way back to #1541.

Was trying to diagnose an issue with improper correction of susceptibility distortions, and this is the first issue I came across (which unfortunately for me is likely not the only issue...). applytopup was doing absolutely nothing to the input data, meaning that the eddy brain mask was aligned with the distorted data, whereas the whole intention of using applytopup is to produce a processing mask that approximates where the brain will be at completion of processing. It turns out that this is because dwifslpreproc was telling applytopup that the phase encoding directions were "k" and "k-", and presumably internally applytopup is deeming this unacceptable and either zeroing out that component of the phase encoding vectors or just code branching to a straight copy-input-to-output. Unfortunately it doesn't provide any indication of this at the terminal.

The stride manipulation within concatenate<vector<Header>>() seems to have been outright incorrect, so I don't think that it should cause any problems, but before merging I might make the same change on dev and run the additional PNG tests in #2713 just to make sure it doesn't have any unintended consequences (existing CI should cover anything else).

- The strides in the aggregate header are expected to already be in absolute rather than symbolic; as such, the former manipulation was inappropriate.
- Only perform manual manipulation of axis strides relative to the hedaer of the first input image in the scenario where concatenation is adding a new axis; if concatenation is occurring across an existing axis, do not perform any manipulation.
Prior to 41c02e9, erroneous phase encoding information was being exported to applytopup:
- The padded DWI series erroneously possessed different strides to the original DWI series.
- The text files to be used by applytopup were being generated by a command that did not explicitly manipulate the strides of the image, whereas the input images provided to applytopup did involve that manipulation.
In addition, it was discovered that applytopup was not performing any manipulation of the data if the phase encoding axis was indicated to be on the third spatial axis; this turns out to have been doing nothing as opposed to an erroneous correction, but given this observation, a check has nevertheless been added to issue a warning where this occurs.
@Lestropie Lestropie requested a review from a team February 15, 2024 01:26
@Lestropie Lestropie self-assigned this Feb 15, 2024
@Lestropie Lestropie marked this pull request as draft February 15, 2024 04:02
Lestropie added a commit that referenced this pull request Feb 15, 2024
- Fix erroneous modification of strides upon header concatenation; this replicates the fix included in 41c02e9 as part of #2806, but is necessary for the suite of fixes here to work. Note that this affects mrcat in addition to multi-image format handling.
- Fix setting of strides upon PNG read.
- Expand testing of PNG handling. Evaluation of read and write functionality is performed separately, with the reference data fully visible and verifiable within the test data repository. Some previous tests bundled read and write testing together, which obscured the erroneous intermediate interpretation.
@Lestropie
Copy link
Member Author

As best as I can ascertain without spending an inordinate amount of time on it, I believe that the bug in 41c02e9 was cancelling out a bug in PNG handling, such that rectification of the former exposes the latter. Plan is to wait for merge of #2713 to master before proceeding here.

Conflicts:
	bin/dwifslpreproc
	core/header.cpp
@Lestropie
Copy link
Member Author

Looks like one of the other parts of this PR, specifically fixing image strides in the circumstance where concatenation is performed along a new additional image axis, was also fixed in 1cc476d as part of #2713. So after bringing this up to date with current master, all that's really left is a bit of code cleanliness.

@Lestropie Lestropie marked this pull request as ready for review July 23, 2025 09:04
@Lestropie Lestropie added this pull request to the merge queue Jul 24, 2025
Merged via the queue into master with commit 554c5ad Jul 24, 2025
5 checks passed
@Lestropie Lestropie deleted the dwifslpreproc_mrcat_strides_fix branch July 24, 2025 06:31
Lestropie added a commit that referenced this pull request Aug 26, 2025
@Lestropie Lestropie restored the dwifslpreproc_mrcat_strides_fix branch August 26, 2025 08:11
@Lestropie Lestropie deleted the dwifslpreproc_mrcat_strides_fix branch August 27, 2025 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants