3

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 fill values, I mask these values before the interpolation.

Input data

I'm using the code below:

tck = interp2d(np.linspace(0, 1200, data.shape[1]),
               np.linspace(0, 1200, data.shape[0]),
               data,
               fill_value=255)
data = tck(range(1200), range(1200))
data = np.ma.MaskedArray(data, data == 255)

I get the following result:

Output data

Fill values have been interpolated.

How can I interpolate my data without interpolate fill values ?

ᴀʀᴍᴀɴ
  • 4,231
  • 7
  • 33
  • 53
Chr
  • 865
  • 1
  • 10
  • 27

1 Answers1

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

Chr
  • 865
  • 1
  • 10
  • 27