This algorithm is inspired by the work of John D'Errico
However, I do notice that the inpaint_nans algorithm given by John D'Ericco gives a higher gradient compared to griddata. So, this algorithm provides an alternative solution that some people may find it helpful.
Kin Sung Chan (2020). Inpaint NaN using Griddata (https://www.mathworks.com/matlabcentral/fileexchange/75758-inpaint-nan-using-griddata), MATLAB Central File Exchange. Retrieved .