imresize和ndimage.interpolation.zoom看起来像他们在做您想要的
我以前没有尝试过imresize,但是这是我使用ndimage.interpolation.zoom的方式
a = np.array(64).reshape(8,8)
a = ndimage.interpolation.zoom(a,.5) #decimate resolution
那么a是一个4x4矩阵,其中有插值
0
imresize和ndimage.interpolation.zoom看起来像他们在做您想要的
我以前没有尝试过imresize,但是这是我使用ndimage.interpolation.zoom的方式
a = np.array(64).reshape(8,8)
a = ndimage.interpolation.zoom(a,.5) #decimate resolution
那么a是一个4x4矩阵,其中有插值
0
因为OP只是想要一个航向分辨率,所以我想我将分享自己的方法,以将每个维度的像素数减少一半。我取2x2块的平均值。可以将其多次应用以减少2倍。
from scipy.ndimage import convolve
array_downsampled = convolve(array,
np.array([[0.25,0.25],[0.25,0.25]]))[:array.shape[0]:2,:array.shape[1]:2]
0
scikit-image
在这里实现了downsampling
的工作版本,尽管如果我理解正确的话,他们不会称其为downsampling
因为它们不是DSP的降采样。
http://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.block_reduce
但它工作得很好,它是我在Python中找到的唯一可以处理图像中np.nan
downsampler
。我很快就对巨大的图像进行了下采样。
0
下采样时,插值是错误的事情。始终使用汇总方法。
我使用块方式来做到这一点,使用“因数”来降低分辨率。
import numpy as np
from scipy import ndimage
def block_mean(ar, fact):
assert isinstance(fact, int), type(fact)
sx, sy = ar.shape
X, Y = np.ogrid[0:sx, 0:sy]
regions = sy/fact * (X/fact) + Y/fact
res = ndimage.mean(ar, labels=regions, index=np.arange(regions.max() + 1))
res.shape = (sx/fact, sy/fact)
return res
例如,使用5的因子(5x5块)的(100,200)形状数组将产生(20,40)数组结果:
ar = np.random.rand(20000).reshape((100, 200))
block_mean(ar, 5).shape # (20, 40)
0
我有基本的二维numpy数组,我想将它们“下采样”到更粗糙的分辨率。是否有一个简单的numpy或scipy模块可以轻松做到这一点?我还要注意,该数组是通过底图模块在地理上显示的。
样品: