I have a 32x32 numpy array representing an image in which 50% values, which amount to 512 pixels, are NaN's. I want to use the griddata function from scipy.interpolate to fill in these missing values so that I can reconstruct the image.
However, I'm having a hard time understanding the griddata function and how exactly to pass my image array to it. The arguments of the function are listed in the documentation but I cannot understand what these arguments mean in the context of my data.
What I understand so far is that the xi
argument indicates the indices in my image array where I want the interpolated values, which I presume would be all the locations where the NaN's are. The values
argument would be my image array but the shape mentioned in the documentation is (n,)
so do I have to flatten the array? And I'm really not sure what the points
argument stands for.
The image array looks something like this:
array([[[ nan, 79., nan, ..., nan, nan, 44.],
[ nan, 84., 45., ..., 48., 84., 44.],
[ nan, nan, 56., ..., 42., 66., 34.],
...,
[126., nan, nan, ..., 70., nan, 133.],
[135., 137., nan, ..., nan, nan, nan],
[142., nan, nan, ..., nan, nan, 151.]]])
Any suggestions would be welcome. Also, is there a better way to interpolate the missing pixel values? Thank you.