# Averaging Model To Model Distances & Getting Value

**URL:** <https://discourse.slicer.org/t/averaging-model-to-model-distances-getting-value/8211>\
**Category:** Support\
**Tags:** 3d-model\
**Created:** [August 28, 2019, 4:56pm UTC](https://discourse.slicer.org/t/averaging-model-to-model-distances-getting-value/8211 "2019-08-28T16:56:49Z")\
**Posts on this page:** 11\
**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:** [August 28, 2019, 4:56pm UTC](https://discourse.slicer.org/t/averaging-model-to-model-distances-getting-value/8211/1 "2019-08-28T16:56:49Z")

</div>

Does anyone know if there is a straightforward way to average the calculated model to model distance models from several samples? This way you can show the average deformation? Also, can you use model to model distance to calculate the total distance between models as a single value?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 29, 2019, 12:17am UTC](https://discourse.slicer.org/t/averaging-model-to-model-distances-getting-value/8211/2 "2019-08-29T00:17:02Z")

</div>

You can retrieve displacement values as a numpy array using `slicer.util.arrayFromModelPointData` and average it using standard numpy operations.

---

<div class="post-metadata">

**Author:** ![ytaneja](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@ytaneja](https://discourse.slicer.org/u/ytaneja)\
**Post date:** [September 11, 2019, 9:42pm UTC](https://discourse.slicer.org/t/averaging-model-to-model-distances-getting-value/8211/3 "2019-09-11T21:42:04Z")

</div>

Would it be possible for you to elaborate on this a bit? I’m confused as to what the “numpy array” is and where it is outputted after running that command in the Python Interactor

Thank you!

---

<div class="post-metadata">

**Author:** ![bpaniagua](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bpaniagua/32/20_2.png) [@bpaniagua](https://discourse.slicer.org/u/bpaniagua)\
**Post date:** [September 12, 2019, 2:35pm UTC](https://discourse.slicer.org/t/averaging-model-to-model-distances-getting-value/8211/4 "2019-09-12T14:35:33Z")

</div>

Yash,

Could you please let us know your experimental set up?  
i.e. i have X models with Y points, I want to do Z

Thanks,  
Bea

---

<div class="post-metadata">

**Author:** ![ytaneja](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@ytaneja](https://discourse.slicer.org/u/ytaneja)\
**Post date:** [September 12, 2019, 6:03pm UTC](https://discourse.slicer.org/t/averaging-model-to-model-distances-getting-value/8211/5 "2019-09-12T18:03:01Z")

</div>

Yes @bpaniagua, I have two models through which I successfully performed the ModelToModelDistance module and this outputted a third model which I have been analyzing using the ShapePopulationViewer module. Though viewing the results using a colormap generated through this process is helpful, I would like to access the numbers behind the colormap to perform further quantitative processing.

Thank you,  
Yash

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 12, 2019, 6:23pm UTC](https://discourse.slicer.org/t/averaging-model-to-model-distances-getting-value/8211/6 "2019-09-12T18:23:53Z")

</div>

> [@ytaneja](#):
>
> Would it be possible for you to elaborate on this a bit? I’m confused as to what the “numpy array” is and where it is outputted after running that command in the Python Interactor

`distances = slicer.util.arrayFromModelPointData(modelNode,'someArrayName')` returns a numpy array that you can process any way you want. You can get point coordinates by calling `point_coords = slicer.util.arrayFromModelPoints(modelNode)`.

> [@ytaneja](#):
>
> I would like to access the numbers behind the colormap to perform further quantitative processing

Lots of analysis tools are available in VTK, SlicerSALT, Slicer, numpy, and various Python packages. We can help more if you can be more specific about what you want to compute.

---

<div class="post-metadata">

**Author:** ![ytaneja](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@ytaneja](https://discourse.slicer.org/u/ytaneja)\
**Post date:** [September 12, 2019, 6:51pm UTC](https://discourse.slicer.org/t/averaging-model-to-model-distances-getting-value/8211/7 "2019-09-12T18:51:25Z")

</div>

@lassoan Thank you for your response. The code still does not work in the Python Interactor – it keeps saying that modelNode is not defined. Maybe the modelNode variable is not accessible just by the Interactor. What do you think?

Also, I am aware of the other modules, but I think that all the analysis I wish to perform can be done if we can get this numpy array to output properly

Thank you!  
Yash

---

<div class="post-metadata">

**Author:** ![ytaneja](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@ytaneja](https://discourse.slicer.org/u/ytaneja)\
**Post date:** [September 12, 2019, 7:07pm UTC](https://discourse.slicer.org/t/averaging-model-to-model-distances-getting-value/8211/8 "2019-09-12T19:07:54Z")

</div>

Another question I had about the Model To Model Distances module is what units does it measure distance in for the colorbar? I’m thinking pixels or micrometers, are either of these correct?

---

<div class="post-metadata">

**Author:** ![ytaneja](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@ytaneja](https://discourse.slicer.org/u/ytaneja)\
**Post date:** [September 12, 2019, 7:34pm UTC](https://discourse.slicer.org/t/averaging-model-to-model-distances-getting-value/8211/9 "2019-09-12T19:34:29Z")

</div>

Update: I was able to generate an array by importing my .vtk file into ParaView and exporting as .csv. However, now I am confused as to what the array means. There are 3 columns and the amount of rows correspond to the amount of points in my vtk. I’m thinking they mean x, y, z but I am not sure, could you confirm this for me?

 ![Snapshot](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/1/2176432d034025bc72d1fbfa4f6518bb8b6e309f.png)

---

<div class="post-metadata">

**Author:** ![ytaneja](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@ytaneja](https://discourse.slicer.org/u/ytaneja)\
**Post date:** [September 16, 2019, 7:11pm UTC](https://discourse.slicer.org/t/averaging-model-to-model-distances-getting-value/8211/10 "2019-09-16T19:11:28Z")

</div>

@lassoan @bpaniagua Could you please refer to my questions above? I just need to confirm units and the meanings behind each column of data. Thank you!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 17, 2019, 4:37am UTC](https://discourse.slicer.org/t/averaging-model-to-model-distances-getting-value/8211/11 "2019-09-17T04:37:30Z")

</div>

> [@ytaneja](#):
>
> The code still does not work in the Python Interactor – it keeps saying that modelNode is not defined

Replace `modelNode` with the variable that refers to your model node. In the Python interactor you typically get is using `modelNode = slicer.util.getNode('Put your model node name here')`, while in a scripted module you usually get it from a node selector widget.

> [@ytaneja](#):
>
> I just need to confirm units and the meanings behind each column of data.

Distances are computed in the same units as you used for point coordinates. In medical image computing, physical coordinate system unit is typically millimeter.

I don’t know what data you found in ParaView. You can get point coordinates, distances, etc. as I described above.
