# Use coefficients to reconstruct 

**URL:** <https://discourse.slicer.org/t/use-coefficients-to-reconstruct/8870>\
**Category:** SlicerSALT\
**Created:** [October 23, 2019, 4:40am UTC](https://discourse.slicer.org/t/use-coefficients-to-reconstruct/8870 "2019-10-23T04:40:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yoda0612](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@Yoda0612](https://discourse.slicer.org/u/Yoda0612)\
**Post date:** [October 23, 2019, 4:40am UTC](https://discourse.slicer.org/t/use-coefficients-to-reconstruct/8870/1 "2019-10-23T04:40:40Z")

</div>

I applied SHPARM-PDM extension, and then obtained the coefficients of spherical harmonic.  
I wonder if I can reconstruct the original mode by just use the coefficients.

---

<div class="post-metadata">

**Author:** ![styner](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/styner/32/1024_2.png) [@styner](https://discourse.slicer.org/u/styner)\
**Post date:** [October 24, 2019, 7:30pm UTC](https://discourse.slicer.org/t/use-coefficients-to-reconstruct/8870/2 "2019-10-24T19:30:26Z")

</div>

Yes, you can. You need to sample the spherical parametrization space and then evaluate the spherical harmonic series at those sample. SlicerSALT is doing that already for you, by using a spherical sampling scheme based on an icosahedron subdivision. The tool that does this is called ParaToSPHARMPDM, which first fits the coefficients and then generates a reconstructed surface from those coefficients.

Martin

---

<div class="post-metadata">

**Author:** ![Yoda0612](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@Yoda0612](https://discourse.slicer.org/u/Yoda0612)\
**Post date:** [October 25, 2019, 6:35am UTC](https://discourse.slicer.org/t/use-coefficients-to-reconstruct/8870/3 "2019-10-25T06:35:07Z")

</div>

Dear Martin,

Thank you for your response.

Actually, I have tried to reconstruct the shapes by the output the spherical harmonic coefficients  
.

Just generated the series of spherical harmonics for each v(phi, theta), and then multiply the coefficients.

However, the result shape is just like a surface.

Because I am trying to develop a tool to apply the spherical harmonic coefficients  
.

I wonder if I miss any other parameters.

Cheng

Martin Styner via 3D Slicer Community [slicer@discoursemail.com](mailto:slicer@discoursemail.com) 於 2019年10月25日 週五 上午4:40寫道：

---

<div class="post-metadata">

**Author:** ![styner](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/styner/32/1024_2.png) [@styner](https://discourse.slicer.org/u/styner)\
**Post date:** [October 25, 2019, 1:42pm UTC](https://discourse.slicer.org/t/use-coefficients-to-reconstruct/8870/4 "2019-10-25T13:42:30Z")

</div>

Not sure what may be wrong in your reconstruction code, but you can look at the code in SlicerSALT:  
surface reconstruction:

> <https://github.com/NIRALUser/SPHARM-PDM/blob/master/Libraries/Shape/Algorithms/SphericalHarmonicMeshSource.cxx>

SPHARM reconstruction at phi/theta:

> <https://github.com/NIRALUser/SPHARM-PDM/blob/master/Libraries/Shape/Numerics/SphericalHarmonicPolynomial.txx>

  
(look at function Evaluate)

Martin

---

<div class="post-metadata">

**Author:** ![Yoda0612](https://avatars.discourse-cdn.com/v4/letter/y/a8b319/32.png) [@Yoda0612](https://discourse.slicer.org/u/Yoda0612)\
**Post date:** [October 28, 2019, 4:54am UTC](https://discourse.slicer.org/t/use-coefficients-to-reconstruct/8870/5 "2019-10-28T04:54:39Z")

</div>

Dear Martin,

Thanks a lot.

Originally, I implemented my code by Python and apply scipy.special.sph\_harm and np.linalg.lstsq to solve the coefficients.

It might have some differences in the details.

I think I can start to modify my code by reference your code.

Regards

Cheng

Regards

Cheng

Martin Styner via 3D Slicer Community [slicer@discoursemail.com](mailto:slicer@discoursemail.com) 於 2019年10月25日 週五 下午10:52寫道：
