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

Incorrect 'normalizedMetric' values if using QuadFit feature of SliceChecker #10

Open
mharms opened this issue Dec 2, 2015 · 1 comment

Comments

@mharms
Copy link
Contributor

mharms commented Dec 2, 2015

Hi,
If you turn on the QuadFit feature of SliceChecker (which to accomplish currently requires setting SliceChecker->SetQuadFit(1) in IntensityMotionCheck.cxx and then re-compiling), the values computed for 'normalizedMetric' are completely wrong. They are intended to be the residuals after fitting the original SliceCheck correlations to a quadratic according to the b-value, but they are far from that.

I tracked the problem down to this bit of code in itkDWIQCSliceChecker.hxx:

  vnl_matrix_fixed<double, 3, 1> coefficients;
  coefficients = vnl_matrix_inverse<double>(bMatrix.transpose() * bMatrix);
  coefficients = coefficients * bMatrix.transpose() * correlationVector;

Note that the variable 'coefficients' is typed to a 3x1 matrix, but then used in an intermediate step to (temporarily) store the output of an inv(X' * X) operation. However, inv(X' * X) is a 3x3 matrix, and the result of the type mismatch is that the full set of 3x3 values is not stored properly. The end result is that the final values for 'coefficients' are wrong, and thus the 'normalizedMetric' values end up being wrong as well.

The fix I implemented was to just create an explicit XtXinv variable, typed to a 3x3 matrix, to store the output of the inv(X' * X) operation:

  vnl_matrix_fixed<double, 3, 1> coefficients;
  vnl_matrix_fixed<double, 3, 3> XtXinv; 
  XtXinv = vnl_matrix_inverse<double>(bMatrix.transpose() * bMatrix);
  coefficients = XtXinv * bMatrix.transpose() * correlationVector;

cheers,
-Mike Harms

@styner
Copy link
Member

styner commented Dec 6, 2015

Hi Mike
Sounds great, thanks for finding and correcting this bug. Can you push the corrected code to the repository? Alternatively just send the modified files to me or Juan via email and we can do so.
Thanks
Martin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants