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

Improvements to qform/sform mismatch check #361

effigies opened this issue Jun 1, 2019 · 0 comments


1 participant
Copy link

commented Jun 1, 2019

Inspired by Neurostars #4379, I think we can make a couple improvements.

  1. Do not warn if qform doesn't change. If the qform and sform don't match exactly, it's possible this is because the sform cannot be exactly represented in the qform fields. Before raising a warning, we could make the following check:

    hdr.set_qform(sform, code)
    if np.allclose(hdr.get_qform(), qform):
        # False alarm
  2. Report the actual change in useful units. It may be that the qform was flipped left-right, rotated 90 degrees, or just wobbled slightly more than floating point rounding error accounts for, but less than would be noticeable by eye. If we give the translation and the total angle of rotation, this could set expectations of what to look for and make the warning less ominous.

    hdr.set_qform(sform, code)
    new_qform = hdr.get_qform()
    diff = np.linalg.inv(qform) @ new_qform
    trans, rot, scale, shear = transforms3d.affines.decompose44(diff)
    axis, angle = transforms3d.axangles.mat2axangle(R)
    total_trans = np.sqrt(np.sum(trans * trans))
    # Add angle and total_trans to report

Both of these would go here:

elif (valid_sform and sform_code > 0) and (not matching_affines or qform_code == 0):
img.set_qform(img.get_sform(), sform_code)
warning_txt = 'Note on orientation: qform matrix overwritten'
description = """\
<p class="elem-desc">The qform has been copied from sform.</p>
if not valid_qform and qform_code > 0:
warning_txt = 'WARNING - Invalid qform information'
description = """\
<p class="elem-desc">
The qform matrix found in the file header is invalid.
The qform has been copied from sform.
Checking the original qform information from the data produced
by the scanner is advised.

For the false alarm, we'll need to adjust some logic:

# Both match, qform valid (implicit with match), codes okay -> do nothing, empty report
if matching_affines and qform_code > 0 and sform_code > 0:
self._results['out_file'] = self.inputs.in_file
open(out_report, 'w').close()
self._results['out_report'] = out_report
return runtime

I think if we made the first three lines of that block unconditional, then we can just return runtime when we find that the qform won't get updated.

@effigies effigies added this to To do in pipelines via automation Jun 1, 2019

@franklin-feingold franklin-feingold moved this from To do to Issues C-list in pipelines Jun 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.