# Principal components analysis in SlicerMorph

**URL:** <https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683>\
**Category:** Support\
**Tags:** slicermorph\
**Created:** [January 25, 2022, 10:01pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683 "2022-01-25T22:01:58Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [January 25, 2022, 10:01pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/1 "2022-01-25T22:01:58Z")

</div>

Is there a limit to the number of points that the principal components can be calculated for using SlicerMorph? Also, if possible, could we create a method for SlicerMorph for iterative closest points in addition to the principal axes? That would probably improve performance on more complex shapes, I believe, and given the inherent nature of SlicerMorph for landmarking and the PseudoLM generator, this doesn’t seem all that infeasible.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [January 25, 2022, 10:38pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/2 "2022-01-25T22:38:45Z")

</div>

No, there is no limit to the number of points as PCA input. Although the more points you have, the bigger VCV matrix and longer it will take for its decomposition.

For SlicerMorph feature suggestions, please use [SlicerMorph’s github issues page](https://github.com/SlicerMorph/SlicerMorph/issues) and provide a detailed description of feature request. It will be great if there is an existing implementation you can refer to for us to better understand what you want to do.

We need to keep track of these in a central location.

---

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [January 27, 2022, 5:00pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/3 "2022-01-27T17:00:22Z")

</div>

Just to check, the module you helped make is part of SLicerMorph now right? I am having a difficult time downloading it if it is.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [January 27, 2022, 5:02pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/4 "2022-01-27T17:02:32Z")

</div>

No, it is not part of the SlicerMorph. AFAIK, at this point it only exists as a script. It needs to be converted to a module, and then we can incorporate as part of the utilities group.  
You are welcomed to send PR for it.

---

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [January 28, 2022, 4:06pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/5 "2022-01-28T16:06:05Z")

</div>

Oh ok. @smrolfe had said that you were going to plan on adding this as a utility to the SlicerMorph extension. Is there anything I can do to help with that process?

> That’s great news. Your previous Slicer installation was much older than the current stable. There have been many bug fixes and new features added since then, so is a good idea to update (either the preview or stable). Thanks for the feedback, we will plan to add this as a utility to the SlicerMorph extension.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [January 28, 2022, 4:26pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/6 "2022-01-28T16:26:08Z")

</div>

There are bunch of things we are working on, and this is not a high priority for us.

But if you want to take on turning it to a module (you can follow the IDAVLMConverter example [SlicerMorph/IDAVLMConverter at master · SlicerMorph/SlicerMorph · GitHub](https://github.com/SlicerMorph/SlicerMorph/tree/master/IDAVLMConverter)), send a PR with changes that will be great.

---

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [January 28, 2022, 4:52pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/7 "2022-01-28T16:52:23Z")

</div>

Didn’t we do this already? I am able to use the module within my 3D Slicer window that has buttons and text options to enter information into it?

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [January 28, 2022, 4:56pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/8 "2022-01-28T16:56:54Z")

</div>

That’s only the python code. For a module to be included into the extension, you need an icon located resources/Icon, you need to specify that it need to be build as part of the extension.  
Look at the example I sent above for IDAVLandmarkEditor. For MorphoJExporter to be a module, you need to have the same structure.

Fork the latest SlicerMorph repo, create a branch for your MorphoJ utility, add the existing python file, create cmakelist and icon, and send a PR.

---

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [January 28, 2022, 6:48pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/9 "2022-01-28T18:48:06Z")

</div>

So I think I managed to do everything. Is this workable: [GitHub - stevenagl12/SlicerMorph-additions: Additional SlicerMorph Extensions](https://github.com/stevenagl12/SlicerMorph-additions.git)

---

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [January 28, 2022, 6:54pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/10 "2022-01-28T18:54:22Z")

</div>

Sorry, missed that last step.

---

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [January 28, 2022, 7:46pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/11 "2022-01-28T19:46:42Z")

</div>

Ok, so I am sorry. I am very confused. I forked the latest SlicerMorph repo, created a branch called additional-extensions, and added in the necessary information, but for some reason it is not only saying that the branch I have is identical to the master repo, but it is also saying that smrolfe edited it 2 days ago…

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [January 28, 2022, 8:22pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/12 "2022-01-28T20:22:57Z")

</div>

Looks like you kept your MorphoJ module as a separate repo. Your fork doesn’t contain any changes:

> **[GitHub - stevenagl12/SlicerMorph: Extensions to conduct 3D morphometrics in...](https://github.com/stevenagl12/SlicerMorph)**
>
> Extensions to conduct 3D morphometrics in Slicer. Contribute to stevenagl12/SlicerMorph development by creating an account on GitHub.

You need to create a folder for the module in SlicerMorph (e.g., ExportMorphoJFile) copy the contents you kept at this repository [GitHub - stevenagl12/SlicerMorph-additions: Additional SlicerMorph Extensions](https://github.com/stevenagl12/SlicerMorph-additions) into that folder.

Then commit and do PR.

---

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [January 28, 2022, 8:43pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/13 "2022-01-28T20:43:14Z")

</div>

So, I had done that already. Here’s a screenshot of the repository on my computer:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/e/ae27cb805f739700b63dc1a82c22f681c5dc037d.png)

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [January 28, 2022, 8:49pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/14 "2022-01-28T20:49:28Z")

</div>

OK. that’s only on your computer.

You need to commit those changes under a new branch, push to your remote repository on GH then request PR.

This might be helpful: [Contributing to Slicer — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/developer_guide/contributing.html#how-to-submit-a-pr)  
Step #2 is not relevant for our case.

---

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [January 28, 2022, 8:58pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/15 "2022-01-28T20:58:02Z")

</div>

I think I managed to do it, and create a pull request. Please let me know if i did it right or if I need to make more changes.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [January 28, 2022, 9:08pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/16 "2022-01-28T21:08:28Z")

</div>

Looks like it worked 👍

---

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [January 28, 2022, 9:11pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/17 "2022-01-28T21:11:42Z")

</div>

I apologize for being so unfamiliar with all this. I never had any formal programming or computer science training, besides MATLAB and LabView, so it is all being picked up as I go along. But thank you for all of your help.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [January 28, 2022, 10:35pm UTC](https://discourse.slicer.org/t/principal-components-analysis-in-slicermorph/21683/18 "2022-01-28T22:35:50Z")

</div>

Np. It is part of the learning. Now you know 🙂
