Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python仿射_变换不转换?_Python_Scipy_Affinetransform - Fatal编程技术网

Python仿射_变换不转换?

Python仿射_变换不转换?,python,scipy,affinetransform,Python,Scipy,Affinetransform,我有一个图像(另存为numpy数组),我想用变换矩阵对其进行变换。 假设transformationatrix是: [[ 0.99729046 -0.07356456 22.57990962] [ 0.07356456 0.99729046 -12.99879896] [ 0. 0. 1. ]] 我想通过'scipy.ndimage.interpolation image=affine\u变换(图像、矩阵、模式=“反射”)

我有一个图像(另存为numpy数组),我想用变换矩阵对其进行变换。 假设transformationatrix是:

[[  0.99729046  -0.07356456  22.57990962]
 [  0.07356456   0.99729046 -12.99879896]
 [  0.           0.           1.        ]]
我想通过'scipy.ndimage.interpolation

image=affine\u变换(图像、矩阵、模式=“反射”)

如果我只是旋转它:

[[  0.99729046  -0.07356456 0.]
 [  0.07356456   0.99729046 0.]
 [  0.           0.         1.]]
它工作得很好,但是当我想旋转它并翻译它,当然只是翻译它,结果看起来很奇怪。我不知道为什么:S

原始图像:

转换图像:

我认为ndimage实际上并不处理彩色图像。它将数组的最后(3,)维视为第三个空间维

你给出的矩阵实际上只是旋转矩阵,而不是仿射矩阵。文件似乎对此不清楚。您应该通过
offset
参数传入移位向量。移位向量还包括“颜色移位”作为第三个元素

这同样适用于特拉维斯·沃特(Travis Vaught)上述评论中的
shift
方法。正确的语法是
ndimage.shift(img,(10.0,10.0,0.0),mode=“wrap”)
——当然,除非你想做一些有趣的颜色变换


原则上,您可以告诉ndimage不要移动等。图像沿颜色轴移动,如上所述,但单独对每个颜色元素进行操作应该会快一些。

这在我看来像是一个bug。我在一个简单的
ndimage.shift(img,10.0,mode=“wrap”)
中看到了同样奇怪的颜色问题。