Spherical-Harmonics-Fitting
This repository contains an unofficial MATLAB re-implementation of selected tools for fitting spherical harmonics in DIPY. In particular, the following tools have been re-implemented:
-
real_sh_descoteaux- returns the real spherical harmonics at the givenm,l,theta,phivalues. -
Ylm- returns the spherical harmonics at the givenm,l,theta,phivalues. This implementation is consistent with the SciPy implementation expect the notation forthetaandphi.- MATLAB and DIPY uses
thetafor the polar angle andphifor the azimuthal angle. - SciPy uses
thetafor the azimuthal angle andphifor the polar angle.
- MATLAB and DIPY uses
-
sf_to_sh- converts a spherical function to the fitted spherical harmonics coefficients. -
sh_to_sf- converts spherical harmonics coefficients to the corresponding spherical function.
In addition, in this toolbox, a helpful tool bvec_to_theta_phi is also included. This tool converts the gradient directions bvec in the Cartesian coordinate system to the corresponding theta and phi values.
Following the convention in dMRI, images are assumed to be of shape H x W x L x N, where H, W, L are the height, width, and length of the image, respectively, and N is the number of gradient directions. Similarly, the gradient directions, bvec, are assumed to be of shape 3 x N.
In Python with DIPY:
from dipy.core.sphere import Sphere
from dipy.reconst.shm import sf_to_sh, sh_to_sf
odf = ... # shape (H, W, L, N)
theta = ... # shape (N,)
phi = ... # shape (N,)
new_theta = ... # shape (M,)
new_phi = ... # shape (M,)
sphere = Sphere(theta=theta, phi=phi)
new_sphere = Sphere(theta=new_theta, phi=new_phi)
sh = sf_to_sh(odf, sphere, 8)
sf = sh_to_sf(sh, new_sphere, 8)Similarly, in MATLAB with this toolbox:
odf = ...; % shape (H, W, L, N)
theta = ...; % shape (N,)
phi = ...; % shape (N,)
new_theta = ...; % shape (M,)
new_phi = ...; % shape (M,)
sh = sf_to_sh(odf, theta, phi, 8);
sf = sh_to_sf(sh, new_theta, new_phi, 8);Detailed versions of the examples can be found here: test.m and test.py.
Accompanying note for Spherical Harmonics Fitting
Spherical Harmonics from SciPy
Descoteaux, M., et al. 2007. Regularized, fast, and robust analytical Q-ball imaging.
Cite As
Kaibo Tang (2025). Spherical-Harmonics-Fitting (https://github.com/kvttt/Spherical-Harmonics-Fitting), GitHub. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Versions that use the GitHub default branch cannot be downloaded
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0 |
|
