BSplineTransform.GetInverse() throws sitk::ERROR: Unable to create inverse

BSplineTransform.GetInverse() throws sitk::ERROR: Unable to create inverse

我使用 the docs 中描述的方法在 Python 中计算了 B 样条变换,并尝试使用 bspline.GetInverse() 对其进行反转。这会导致以下错误:

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!

有什么办法可以求逆吗?

这是关于 B 样条变换逆向的 ITK 讨论的主题:

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

它没有在 ITK 中实现,但他们描述了一种通过变形场实现逆的方法。

虽然这样变换整个图像会很慢,但我只需要变换几个点,因此最终使用 scikit 优化来找到一个点的倒数:

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