1

I calculated a B-spline transform in Python using the method described in the docs, and trying to invert it using bspline.GetInverse(). This causes the following error:

Traceback (most recent call last):

...

  File "/home/ml/PycharmProjects/venv36_general/lib/python3.6/site-packages/SimpleITK/SimpleITK.py", line 5236, in GetInverse
    return _SimpleITK.Transform_GetInverse(self)
RuntimeError: Exception thrown in SimpleITK Transform_GetInverse: /tmp/SimpleITK/Code/Common/src/sitkTransform.cxx:622:
sitk::ERROR: Unable to create inverse!

Anything that can be done to get the inverse?

Michael Litvin
  • 3,976
  • 1
  • 34
  • 40

2 Answers2

1

Though this would be slow to transform the entire image, I just needed to transform several points, and thus ended up using scikit optimization to find the inverse of a point:

def inverse_transform_point(xform, p):
    """
    Returns the inverse-transform of a point.

    :param sitk.Transform xform: The transform to invert
    :param (float,float)|[float|float]|np.ndarray p: The point to find inverse for
    :return np.ndarray, bool: The point and whether the operation succeeded or not
    """

    def fun(x):
        return np.linalg.norm(xform.TransformPoint(x) - p)

    p = np.array(p)
    res = minimize(fun, p, method='Powell')
    return res.x, res.success
Michael Litvin
  • 3,976
  • 1
  • 34
  • 40
0

Here's a thread on the ITK discourse about the inverse of a BSpline transform:

https://discourse.itk.org/t/inverse-of-bspline-transform/496/2

It is not implemented in ITK, but they describe a way to achieve an inverse via a deformation field.

Dave Chen
  • 1,905
  • 1
  • 12
  • 18