我正在处理拟合图像,并尝试将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?
答案 0 :(得分:0)
这对我有用:
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)