Skip to content Skip to sidebar Skip to footer

Scipy Interp2d Interpolate Masked Fill Values

I want to interpolate data (120*120) in order to get output data (1200*1200). In this way I'm using scipy.interpolate.interp2d. Below is my input data, where 255 corresponds to fil

Solution 1:

I found a solution with scipy.interpolate.griddata but I'm not sure that's the best one.

I interpolate data with the nearest method parameter which returns the value at the data point closest to the point of interpolation.

points = np.meshgrid(np.linspace(0, 1200, data.shape[1]),
                     np.linspace(0, 1200, data.shape[0]))
points = zip(points[0].flatten(), points[1].flatten())
xi = np.meshgrid(np.arange(1200), np.arange(1200))
xi = zip(xi[0].flatten(), xi[1].flatten())

tck = griddata(np.array(points), data.flatten(), np.array(xi), method='nearest')
data = tck.reshape((1200, 1200))

Output data

Post a Comment for "Scipy Interp2d Interpolate Masked Fill Values"