Python 相当于 IDL median() 和 rot()

Python equivalent to IDL median() and rot()

我正在处理合适的图像并尝试将 IDL 代码转换为 python,但我无法理解如何转换 IDL median()rot() 函数。我有一个数组 im_darksub,它是 (ny, nx, n_im),其中 nx,ny 是每个图像的形状,n_im 是图像的数量(总共处理 12 张图像)。我试图翻译 IDL 代码 im_median = median(im_darksub,dimension=1)im_medrot = rot(im_median,85,cubic=-0.5)。我以为我可以将其翻译成 np.median()spicy.misc.imrotate,但是当我使用 imrotate:

时,我一直收到错误消息
    Traceback (innermost last):
      File "<console>", line 1, in <module>
      File "/Users/courtneywatson1/Ureka/python/lib/python2.7/site-packages/scipy/misc/pilutil.py", line 345, in imrotate
        im = toimage(arr)
      File "/Users/courtneywatson1/Ureka/python/lib/python2.7/site-packages/scipy/misc/pilutil.py", line 234, in toimage
        raise ValueError("'arr' does not have a suitable array shape for "
    ValueError: 'arr' does not have a suitable array shape for any mode.

我猜这是因为我的图像阵列超过 2 维还是 3D? IDL median()rot() 是否有与我使用它们的方式相同的 python 功能?

这对我有用:

import numpy as np
x = np.arange(100)
x = np.reshape(x, (5, 5, 4))
im_median = np.median(x, axis=2)

import scipy.misc
im_rotate = scipy.misc.imrotate(y, 85, 'cubic')

而且我假设您已经看到 imrotate 已被弃用:

/Users/mgalloy/anaconda3/bin/ipython:1: DeprecationWarning: `imrotate` is deprecated!
`imrotate` is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use ``skimage.transform.rotate`` instead.

这似乎工作得很好:

import skimage.transform
im_rotate = skimage.transform.rotate(im_median, 85, order=3, preserve_range=True)