Hi all,
I am trying to input the SH coefficient of a voxel to calculate the peak direction in Python. I wonder if there are API or python code available? Or could anyone share the computing method, so that I can write the code by myself?
Many thanks!
Hi @RosieZhou,
I’m afraid there is no Python API for that functionality. It’s fairly deep in the C++, and while it would be possible to expose that as a Python API, that would require quite a bit of work. For reference, this is the relevant code – but I wouldn’t want to implement all that in Python… It’s essentially a version of the Newton-Raphson algorithm adapted to work better over spherical coordinates. It converges very quickly (typically 5 iterations), but it requires calculation of the second-order derivatives of the spherical harmonic series – not fun, unless you like that kind of thing…
You may find it much easier to use different types of approaches that don’t require calculation of the gradients. I suspect it would be relatively straightforward to implement the Nelder-Mead simplex – though I expect it would be considerably slower than our approach.
Another alternative if you don’t need high precision is just to evaluate the amplitude along a very dense set of uniformly distributed directions, and pick the highest value. Not pretty, but it’ll do the job if you only need to be within a few degrees of the actual peak direction…
Hope this helps…
All the best,
Donald.