megengine.functional.vision.remap

remap(inp, map_xy, border_mode='replicate', scalar=0.0, interp_mode='linear')[源代码]

对按批组织的二维图像进行重映射变换。

输入图像通过张量 map_xy 变换为输出图像。输出的高度与宽度与 map_xy 中一致。

参数
  • inp (Tensor) – 输入图像

  • map_xy (Tensor) – (batch, oh, ow, 2) 变换矩阵。

  • border_mode (str) – pixel extrapolation method. Default: “replicate”. Currently also support “constant”, “reflect”, “reflect_101”, “wrap”.

  • scalar (float) – 边界填充值。 默认:0

  • interp_mode (str) – interpolation methods. Default: “linear”. Currently only support “linear” mode.

返回类型

Tensor

返回

输出张量。

例如:

import numpy as np
from megengine import tensor
import megengine.functional as F
inp_shape = (1, 1, 4, 4)
inp = tensor(np.arange(16, dtype=np.float32).reshape(inp_shape))
map_xy_shape = (1, 2, 2, 2)
map_xy = tensor(np.array([[[1., 0.],[0., 1.]],
                    [[0., 1.],[0., 1.]]],
                     dtype=np.float32).reshape(map_xy_shape))
out = F.vision.remap(inp, map_xy)
print(out.numpy())

输出:

[[[[1. 4.]
   [4. 4.]]]]