python:skimage.transform.AffineTransform旋转中心

python:skimage.transform.AffineTransform旋转中心,python,rotation,scikit-image,Python,Rotation,Scikit Image,我试图在python中使用skimage在opencv中旋转图像: 其中,“中心”是源图像中旋转的中心 在skimage中,相应的转变似乎是: 但我不知道如何定义旋转的中心。。。。是否有其他方法来定义旋转中心(或者可能有另一种撇渣方法?) 我已经查看了web和手册,目前没有发现任何内容…通过结合以下转换,目前这是可能的: 移动图像,使中心位于原点周围 旋转N度 将图像向后移动 然而,一个单一的参数将使这更容易!请您在GitHub上提交一个问题,以便我们能够实现这一点,好吗 与此同时,守则: fr

我试图在python中使用skimage在opencv中旋转图像:

其中,“中心”是源图像中旋转的中心

在skimage中,相应的转变似乎是:

但我不知道如何定义旋转的中心。。。。是否有其他方法来定义旋转中心(或者可能有另一种撇渣方法?)


我已经查看了web和手册,目前没有发现任何内容…

通过结合以下转换,目前这是可能的:

  • 移动图像,使中心位于原点周围
  • 旋转N度
  • 将图像向后移动
  • 然而,一个单一的参数将使这更容易!请您在GitHub上提交一个问题,以便我们能够实现这一点,好吗

    与此同时,守则:

    from skimage import data
    from skimage import transform
    import numpy as np
    import matplotlib.pyplot as plt
    
    image = data.chelsea()
    
    shift_y, shift_x = np.array(image.shape[:2]) / 2.
    tf_rotate = transform.SimilarityTransform(rotation=np.deg2rad(30))
    tf_shift = transform.SimilarityTransform(translation=[-shift_x, -shift_y])
    tf_shift_inv = transform.SimilarityTransform(translation=[shift_x, shift_y])
    
    image_rotated = transform.warp(image, (tf_shift + (tf_rotate + tf_shift_inv)).inverse)
    
    plt.imshow(image_rotated)
    plt.show()
    

    Stefan答案中的图像中心似乎不正确,下面是他的代码的更正版本

    from skimage import transform
    import numpy as np
    import matplotlib.pyplot as plt
    
    image = np.zeros([21, 21])
    image[10,:] = 1
    image[10,10] = 5
    image[7, 10] = 1
    
    shift_y, shift_x = (np.array(image.shape)-1) / 2.
    tf_rotate = transform.SimilarityTransform(rotation=np.deg2rad(60))
    tf_shift = transform.SimilarityTransform(translation=[-shift_x, -shift_y])
    tf_shift_inv = transform.SimilarityTransform(translation=[shift_x, shift_y])
    image_rotated = transform.warp(image, (tf_shift + (tf_rotate + tf_shift_inv)).inverse, order = 3)
    
    
    plt.subplot(121)
    plt.imshow(image)
    plt.subplot(122)
    plt.imshow(image_rotated)
    plt.show()
    
    print "original image maximum at: ", np.unravel_index(np.argmax(image), image.shape)
    print "rotated image maximum at : ", np.unravel_index(np.argmax(image_rotated), image_rotated.shape)
    
    原始图像最大值为:(10,10)
    旋转图像最大值为:(10,10)

    我在这里添加了一个问题:必须注意的是,对于相似性/仿射变换,这个问题并没有得到解决。唯一固定的变换是旋转。我们不打算为单个变换“固定”旋转:这些变换本身没有中心。相反,你可以使用上面概述的程序。老实说,我看不出有什么区别。旋转变换只是仿射变换的一种特殊情况。您也可以将上面概述的过程用于旋转变换,但为旋转提供了一个中心参数。所有变换都假定变换的原点必须是图像的(0,0)。您可以根据需要轻松地使用一个参数来更改该假设。我想我认为
    rotate
    是一个方便的函数,而Transform对象本身是更低级的原语。但是,我看到我们已经提供了至少仿射和相似性的参数初始化,所以我们可以添加它。这不是一个高优先级,但我们将审查公关,如果提供。
    from skimage import data
    from skimage import transform
    import numpy as np
    import matplotlib.pyplot as plt
    
    image = data.chelsea()
    
    shift_y, shift_x = np.array(image.shape[:2]) / 2.
    tf_rotate = transform.SimilarityTransform(rotation=np.deg2rad(30))
    tf_shift = transform.SimilarityTransform(translation=[-shift_x, -shift_y])
    tf_shift_inv = transform.SimilarityTransform(translation=[shift_x, shift_y])
    
    image_rotated = transform.warp(image, (tf_shift + (tf_rotate + tf_shift_inv)).inverse)
    
    plt.imshow(image_rotated)
    plt.show()
    
    from skimage import transform
    import numpy as np
    import matplotlib.pyplot as plt
    
    image = np.zeros([21, 21])
    image[10,:] = 1
    image[10,10] = 5
    image[7, 10] = 1
    
    shift_y, shift_x = (np.array(image.shape)-1) / 2.
    tf_rotate = transform.SimilarityTransform(rotation=np.deg2rad(60))
    tf_shift = transform.SimilarityTransform(translation=[-shift_x, -shift_y])
    tf_shift_inv = transform.SimilarityTransform(translation=[shift_x, shift_y])
    image_rotated = transform.warp(image, (tf_shift + (tf_rotate + tf_shift_inv)).inverse, order = 3)
    
    
    plt.subplot(121)
    plt.imshow(image)
    plt.subplot(122)
    plt.imshow(image_rotated)
    plt.show()
    
    print "original image maximum at: ", np.unravel_index(np.argmax(image), image.shape)
    print "rotated image maximum at : ", np.unravel_index(np.argmax(image_rotated), image_rotated.shape)