add comments for Volume.resize() method#80
Merged
Conversation
yhuang43
commented
Jun 23, 2026
Contributor
surfa.Volume.resize() and freesurfer MRIupsampledN()/MRIdownsampleN() works differently.
surfa.Volume.resize() logic:
1. keep the original image 'rotation' and 'center' parameters when computing the resampled image geom
2. resampled image crs0 remains the same as originial image. This may cause all voxels to be interpolated
3. force the originial and resampled image in the same RAS space when computing target-source vox2vox matrix
4. by default, 'linear' interpolation method is used
MRIupsampledN()/MRIdownsampleN() logic:
1. the RAS of a voxel is at the center of the voxel, so the image corner is located at CRS = [-.5 -.5 -.5]
2. the center of the resampled image crs0 = -0.5 + 1.0 / (2 * factor) in originial image voxel space (generally used in FS code)
3. the original and resampled images share the same RAS space (implicit)
4. the resampled image p0ras can be computed as p0ras = aff_orig @ crs0
5. re-compute the resampled image 'center' parameters after correcting p0ras of aff_resampled
6. The way the offset/center is set up, some voxels will fall in the same spot as the original volume which means they will not have any interpolation effects.
The target vox2ras from surfa.Volume.resize() and freesurfer MRIupsampledN()/MRIdownsampleN() are different,
but they share the same RAS space. Because the resulting target-source vox2vox is different, surfa.Volume.resize()
interpolates the voxel values from locations that are different from MRIupsampledN()/MRIdownsampleN().
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.