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

get_voxel_spacing utility function #1627

Closed
cancan101 opened this issue Mar 21, 2018 · 6 comments
Closed

get_voxel_spacing utility function #1627

cancan101 opened this issue Mar 21, 2018 · 6 comments

Comments

@cancan101
Copy link
Contributor

From here:

# Identify the voxel size using a QR decomposition of the
# affine
Q, R = np.linalg.qr(affine[:3, :3])
target_affine = np.diag(np.abs(np.diag(R))[
np.abs(Q).argmax(axis=1)])

factor out:

def get_voxel_spacing(affine):
    Q, R = np.linalg.qr(affine[:3, :3])
    return np.abs(np.diag(R))[np.abs(Q).argmax(axis=1)]

This function is useful for example when resizing to isotropic you can use the smallest dimension in the new affine.

@KamalakerDadi
Copy link
Contributor

Isnt't this simple to grab the diagonal of the affine ? Why do we need function ?

You mean we can use this function multiple places in the code base ?

@cancan101
Copy link
Contributor Author

It isn't quite the (raw) diagonal of the affine. It is doing a QR decomposition.

@KamalakerDadi
Copy link
Contributor

yeah but the result will be the same. isn't it ?

@cancan101
Copy link
Contributor Author

Take this as an example:

array([[4, 1, 3],
       [1, 0, 0],
       [0, 0, 2]])
> get_voxel_spacing(arr)
array([4.12310563, 0.24253563, 2.        ])

@bthirion
Copy link
Member

Well, can you issue a PR ?

@bthirion
Copy link
Member

Stalled.

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

3 participants