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

Jacobian for B-spline #40

Open
Mikerov opened this issue Apr 30, 2022 · 1 comment
Open

Jacobian for B-spline #40

Mikerov opened this issue Apr 30, 2022 · 1 comment

Comments

@Mikerov
Copy link

Mikerov commented Apr 30, 2022

Is there a way to calculate the determinant of the Jacobian to see whether the used B-spline transformation is volume preserving? What alternative methods can I use to ensure that there is no shrinkage?

@koegl
Copy link

koegl commented Jun 12, 2024

import SimpleITK as sitk

def jacobian_determinant_from_displacement(displacement: np.ndarray) -> np.ndarray:

    displacement = displacement.squeeze()

    assert displacement.ndim == 4, "Displacement field should have shape (h, w, d, 3)"
    
    # transpose if necessary 
    if displacement.shape[-1] != 3 and displacement.shape[0] == 3:
        displacement = displacement.transpose(1, 2, 3, 0)

    displacement_image = sitk.GetImageFromArray(displacement, isVector=True)
    jacobian_determinant_image = sitk.DisplacementFieldJacobianDeterminant(
        displacement_image)
    return sitk.GetArrayFromImage(jacobian_determinant_image)

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