Reputation: 3819
I have a program in which I am querying all points included in a sphere S of radius R. The points are 3D points actually aligned on the vertices of a 3D regular grid, but I don't think this detail is relevant to the question. The center of the lookup volume (the sphere) can be anywhere in 3D pace.
The points hold some data (say a real). My question, is how can I interpolate/filter the data held by the points which are included in the sphere using a 3D filter (such as gaussian filter for instance). My understanding is that you need to do something like this (pseudo code):
interp_data = 0;
for (each point contained in the lookup sphere S of radius R)
// compute square distance from point location to sphere centre
dist2 = distance2(sphere_center, curr_point_loc);
// compute gaussian weight
w = exp(-100 * dist2);
sumWeight += w;
interp_data += curr_point_data * w;
interp_data /= sumWeight;
Is it correct. I have seen some code using a similar technique. I understand the value 100 on the exp function relates somehow to what seems to be called the standard normal deviation. The value 100 was hard coded in the source code that I have seen, but I assume this should somehow relate to the radius of the sphere? As the weight of the gaussian filter is supposed to drop to 0 when dist2 = R^2.
If someone could shed some light on this it would be great.
Also is it actually the best way of filtering 3D data? Is there a better/faster/more reliable method?
Thanks a lot for your help.
Upvotes: 3
Views: 7508
Reputation: 26345
Your proposal is mostly reasonable, though probably not efficient. (Also, why distance squared and not just distance?)
You can perform a 3D Gaussian more efficiently by doing the following things:
1) Separate out the kernel into 3 1-dimensional passes with a 1D Gaussian kernel. This is explained on the Gaussian blur wikipedia page
2) You can approximate a Gaussian kernel by doing a box-blur several times in a row, and which you can implement by using summed area tables
3) You could also use a fast fourier transform and do the convolution by multiplying the image by the kernel in frequency space instead.
Upvotes: 9