为了账号安全,请及时绑定邮箱和手机立即绑定

使用 ndimage.interpolation.affine_transform 进行矩阵平移

使用 ndimage.interpolation.affine_transform 进行矩阵平移

米脂 2021-06-30 18:40:15
我正在尝试使用 翻译一个简单的矩阵ndi.interpolation.affine_transform,但我得到的结果是相反的。例如:import scipy.ndimage as ndim = [[1, 1, 11], [2, 2, 22], [3, 3, 33]]final_affine_matrix = [[1, 0], [0, 1]]final_offset = [0, 1]x = ndi.interpolation.affine_transform(        m,        final_affine_matrix,        final_offset,        order=1,        mode='nearest',        cval=0)print(x)[[ 1 11 11] [ 2 22 22] [ 3 33 33]]鉴于偏移量为[0, 1],不应该移动 y 轴而不是 x 轴吗?也就是说,输出不应该是:[[ 2  2 22] [ 3  3 33] [ 3  3 33]]我可以达到那个结果,但只能使用 offset [1, 0]。他们不应该是相反的吗?
查看完整描述

1 回答

?
忽然笑

TA贡献1806条经验 获得超5个赞

如文档中所述,scipy.ndimage.affine_transform()通过执行以下操作来计算新位置:(np.dot(matrix, o) + offset其中o是输出位置)。


这意味着以下测试应该会成功:


m = np.array(m)

assert(m[0, 1] == x[0, 0])

assert(m[0, 2] == x[0, 1])

assert(m[1, 1] == x[1, 0])

assert(m[1, 2] == x[1, 1])

assert(m[2, 1] == x[2, 0])

assert(m[2, 2] == x[2, 1])

或者,更简洁地说:


assert(np.all(m[:, 1] == x[:, 0]))

assert(np.all(m[:, 2] == x[:, 1]))

正如预期的那样,他们做到了。所以,实际上矩阵正在被1-index移动。也许,您期望另一个矩阵作为输出,因为您对打印的输出感到困惑。第零个索引表示行,第一个索引表示列。因此,按第一个索引移动将移动列。


查看完整回答
反对 回复 2021-07-06
  • 1 回答
  • 0 关注
  • 268 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号