2013-09-06 5 views
1

나는 다른 시간에 그리드의 양 값을 나타내는 두 개의 행렬을가집니다. 중간 시간에 세 번째 행렬을 만들고 싶습니다.이 행렬의 픽셀은 두 행렬 사이에 삽입됩니다.두 행렬 간의 보간

각 픽셀에 대해 간단한 선형 보간을 시도했지만, 최종 제품을 imshow으로 시각화하면 프레임간에 부드러운 전환이 발생하지 않습니다.

거대한 데이터 세트를 다루고 있기 때문에 직접적인 예는 제공 할 수 없지만 비슷한 문제가 있었던 사람이 있는지 궁금해하고있었습니다.

나는 scipy.interpolate 함수를 알고 있지만 이산 점 집합을 보간하기 위해서만 유용하게 보입니다.

+0

무엇에 대한 ['scipy.interpolate.griddata'] (HTTP : //docs.scipy합니다. org/doc/scipy/reference/generated/scipy.interpolate.griddata.html # scipy.interpolate.griddata)? "크기 배열 (N, ndim) 또는 ndim 배열의 튜플"을 취합니다. –

답변

2

, 당신은 보간 ndimage.map_coordinates을 사용할 수

import numpy as np 
import scipy.ndimage as ndimage 
import matplotlib.pyplot as plt 

# given 2 arrays arr1, arr2 
arr1 = np.linspace(0, 1, 100).reshape(10,10) 
arr2 = np.linspace(1, 0, 100).reshape(10,10) 

# rejoin arr1, arr2 into a single array of shape (2, 10, 10) 
arr = np.r_['0,3', arr1, arr2] 

# define the grid coordinates where you want to interpolate 
X, Y = np.meshgrid(np.arange(10), np.arange(10)) 
# 0.5 corresponds to half way between arr1 and arr2 
coordinates = np.ones((10,10))*0.5, X, Y 

# given arr interpolate at coordinates 
newarr = ndimage.map_coordinates(arr, coordinates, order=2).T 
fig, ax = plt.subplots(ncols=3) 
cmap = plt.get_cmap('Greys') 

vmin = np.min([arr1.min(), newarr.min(), arr2.min()]) 
vmax = np.max([arr1.max(), newarr.max(), arr2.max()]) 
ax[0].imshow(arr1, interpolation='nearest', cmap=cmap, vmin=vmin, vmax=vmax) 
ax[1].imshow(newarr, interpolation='nearest', cmap=cmap, vmin=vmin, vmax=vmax) 
ax[2].imshow(arr2, interpolation='nearest', cmap=cmap, vmin=vmin, vmax=vmax) 
ax[0].set_xlabel('arr1') 
ax[1].set_xlabel('interpolated') 
ax[2].set_xlabel('arr2') 
plt.show() 

enter image description here

2

NumPy와 배열로 행렬을 가정하고 두 점을 가지고 오직 한 이후, 당신은 단순히 (선형)을 구현할 수있는 자신을 보간 :

def interp(m1, t1, m2, t2, t_interp): 
    return m1 + (m2-m1)/(t2-t1) * (t_interp-t1) 

m1/m2 임의로 형성 할 수있다 NumPy와 배열을하고 t1/t2 해당 시간 값. t_interp는 보간 할 시간 값이됩니다. 그러면 m1t_interp = t1이고 m2t_interp = t2입니다. 원래의 데이터가 이미 격자되어 있기 때문에

+0

답변을 주셔서 감사합니다. 그러나 제가 말씀 드렸듯이 이것은 제가 전에 시도했던 질문입니다. 더 복잡한 방법이 있습니까? – Brian