Conversation
Member
Author
|
Let's roll it out and come back to this if @effigies disagrees. |
effigies
reviewed
Aug 19, 2024
Comment on lines
+665
to
678
|
|
||
| # Read slope and intercept (see #1315) | ||
| slope, intercept = full_img.header.get_slope_inter() | ||
| slope = slope if slope is not None else 1.0 | ||
| intercept = intercept if intercept is not None else 0.0 | ||
| corrected = ( | ||
| full_img.get_fdata() * fitted[np.newaxis, np.newaxis, np.newaxis, :] / slope | ||
| - intercept | ||
| ) | ||
| full_img.__class__( | ||
| (full_img.get_fdata() * fitted[np.newaxis, np.newaxis, np.newaxis, :]).astype( | ||
| full_img.header.get_data_dtype() | ||
| ), | ||
| corrected.astype(full_img.header.get_data_dtype()), | ||
| full_img.affine, | ||
| full_img.header, | ||
| ).to_filename(self._results['out_full_file']) |
Member
There was a problem hiding this comment.
Sorry for the delay. No, you just want:
full_img.__class__(
full_img.get_fdata() * fitted[np.newaxis, np.newaxis, np.newaxis, :],
full_img.affine
full_img.header
).to_filename(self._results['out_full_file'])You pretty much never want to dynamically coerce the type. All of nibabel's machinery assumes that the data is valid and that the header encodes the intent, and will perform scaling on your behalf if continuous data needs to be discretized into an integer dtype.
Member
Author
There was a problem hiding this comment.
I assume that applies the slope and intercept when generating the spatialimage object, correct?
Member
There was a problem hiding this comment.
Yes, it will calculate a new slope and intercept based on the min/max values of the data array.
oesteban
added a commit
that referenced
this pull request
Aug 19, 2024
Co-authored-by: Chris Markiewicz <effigies@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses the issue reported by @psadil with his proposed solution 1 (considering the slope and intercept).
cc/ @effigies for a correctness check.
Resolves: #1315.