如何加速scipy.ndimage.geometric_transform?

2024-05-21 14:01:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将基于scipy.interpolate.Rbf拟合的3D图像转换为位移场。所以我必须独立地插值每个坐标

# scipy.interpolate.Rbf fitting
# coordinate_mapping contains the x y z positions of tracked positions
interp_mapping = tuple(Rbf(*coordinate_mapping[:, :, 0].T, coordinate_mapping[:, x, 1], function="thin_plate") for x in range(3))

class interpolated_field:
    """Helper class just to have a callable vector field to put into transformation functions"""
    def __init__(self, field_tuple):
        self.field_tuple=field_tuple
    def __call__(self, coords):
        return tuple(self.field_tuple[x](*coords) for x in range(3))

interp_field = interpolated_field(interp_mapping)

然后我用

# transposed_frame is of shape (632, 352, 35)
inverse_transformed = geometric_transform(transposed_frame, interp_field, prefilter=False)

但是在一个帧上执行转换大约需要13分钟,我想做几百次。这个功能有更快的版本吗?或者以某种方式将其多线程或发送到GPU


Tags: ofinselffieldcoordinateforrangescipy