-
Notifications
You must be signed in to change notification settings - Fork 261
Function to rescale an affine matrix #670
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
Comments
@effigies I think this is a nice way of dealing with the rotation and shear components:
|
@Shotgunosine helped me figure out the scaling of the translation if that is desired too. Something along the lines of:
And then to tie it altogether to resample an image given a target_shape and voxel dimensions:
|
|
@effigies : I am trying to figure what will be the new translation values in case of scaling. Lets say we have new scale and old scale. I was going thru @ellisdg's code and he has used something like this (https://github.com/ellisdg/3DUnetCNN/blob/master/unet3d/utils/affine.py) def calculate_origin_offset(new_spacing, old_spacing): Another question is leveraging other libraries like skimage and torchio. How resize/transform in skimage/ torchio approach is different from scaling affine first and then using resample_img from nilearn https://stackoverflow.com/questions/64674612/how-to-resize-a-nifti-nii-gz-medical-image-file |
Given that
image.header.set_zooms()
does not update an affine, a useful tool would be a function that takes a given affine matrix and returns an updated matrix that encodes the desired zooms.Adapting from @ellisdg's suggestions:
The correct way to fix the zooms on a file would then be:
This approach would leave the RAS coordinates of
(i, j, k) = (0, 0, 0)
the same. It may be desirable instead to adjust the translation so that the IJK coordinates of the RAS origin are constant. Possibly controlled by a parameter.I'm not absolutely positive that this handles shear components correctly. I'd need to check.
Sub-issue identified in #619.
The text was updated successfully, but these errors were encountered: