I have a cloud point obtained from photogrammetry from a person’s back. I’m trying to interpolate it to get a regular grid, and for that I’m using scipy.interpolate with good results so far. The problem is: the function I’m using (scipy.interpolate.griddata) uses the convex hull of the cloudpoint in the plane x,y, thus giving as result some values that don’t exist in the original surface, which has a concave perimeter.
The following illustration shows the original cloudpoint at the left (what is displayed as horizontal lines is actually a dense line-shaped cloud of points), the result that griddata gives me in the middle, and the result I would like to get at the right — kind of the “shadow” of the cloudpoint on the x,y plane, where non-existing points in the original surface would be zeros or Nans.

I know I could remove the Z coordinate on the cloudpoint and check each grid position for proximity, but this is so brute-force, and I believe this should be a common problem on point-cloud applications.
Another possibility could be some numpy operation to perform over the point-cloud, finding a numpy mask or boolean 2D-array to “apply” over the result from griddata, but I didn’t find any (these operations are a bit beyond my Numpy/Scipy knowledge).
Any suggestion?
Thanks for reading!
Suitable masks can be constructed fast using
KDTree. The interpolation algorithm used by griddata does not have a notion of “valid” points, so you need to adjust your data either before or after the interpolation.Before:
The idea is to “seed” the input data with fake data points containing
nanvalues. When using linear interpolation, these will blot out areas of the image that have no actual data points nearby.You can also blot out invalid data after the interpolation: