# Mean Shape Calculation

**URL:** <https://shapeworks.discourse.group/t/mean-shape-calculation/320>\
**Category:** Uncategorized\
**Created:** [February 18, 2025, 7:16am UTC](https://shapeworks.discourse.group/t/mean-shape-calculation/320 "2025-02-18T07:16:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ragavan](https://avatars.discourse-cdn.com/v4/letter/r/c5a1d2/32.png) [@Ragavan](https://shapeworks.discourse.group/u/Ragavan)\
**Post date:** [February 18, 2025, 7:16am UTC](https://shapeworks.discourse.group/t/mean-shape-calculation/320/1 "2025-02-18T07:16:55Z")

</div>

Hello Alan ,

I am working for knee bone morphing , initially i am trying with 22 left Femurs , i groomed using (ICP) alignment data (input in .stl format) , and i did the optimization in the shape works studio .  
now my current goal is to create the **mean shape** of 22 left Femurs

now i have a few questions to ask you for more clarification ?

1.can the shape works studio can create the mean shape of 22 left Femur bones?

1. if yes means , how to do that in the shape works studio ?

2. i have tried with only groomed\_world.particles files to generate the mean shape using python.

3. I am tried with PythonAPI with groomed\_world.particles to generate to mean shape of 22 left femur but i could not do that , that why i am asking what are files required to mean shape of anatomy (groomed icp alignment .vtk files , groomed\_local.particles , groomed\_world.particles )

Here is the code for generating the mean shape using only world.particles

import shapeworks as sw  
import os  
import glob

# Step 1: Define folder path for knee particle files

particle\_files\_folder = “/home/ragavan/shapeworks/Femur/knee\_particles/”

# Step 2: Load only ‘world’ particle files from the folder

particle\_files = sorted(glob.glob(os.path.join(particle\_files\_folder, “_world_.particles”)))

# Check if files are found

if not particle\_files:  
raise ValueError(f"No world particle files found in {particle\_files\_folder}")

# Step 3: Initialize a Project

project = sw.Project()

# Step 4: Add subjects (particles) to the Project

for particle\_file in particle\_files:  
project.add\_subject(particle\_file) # Ensure the correct method to add particles to the project

# Step 5: Create an Analyze object by passing the project

analyze = sw.Analyze(project)

# Step 6: Compute the mean shape points using the Analyze class

mean\_shape\_points = analyze.get\_mean\_shape\_points()

# Step 7: Save the mean shape as a VTK file

mean\_shape\_output\_path = “/home/ragavan/shapeworks/mean\_shape\_world.vtk”  
sw.Mesh(mean\_shape\_points).write(mean\_shape\_output\_path)

print(f"Mean shape saved to {mean\_shape\_output\_path}")

---

<div class="post-metadata">

**Author:** ![amorris](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@amorris](https://shapeworks.discourse.group/u/amorris)\
**Post date:** [February 22, 2025, 12:16am UTC](https://shapeworks.discourse.group/t/mean-shape-calculation/320/2 "2025-02-22T00:16:14Z")

</div>

Yes, if you create a shape model, you can export the mean shape in ShapeWorks Studio. When the mean shape is displayed in the analysis module, you can right click on the shape and select “export mesh”. You can also use File-\>Export-\>Export Current Mesh, or Export Current Particles for the particles.

With the Python API, you can use the Analyze class:

> **[Python API Reference - ShapeWorks](http://sciinstitute.github.io/ShapeWorks/latest/python/python-api.html#shapeworks_py.Analyze)**
>
> The official documentation of ShapeWorks

E.g. Analyze.get\_mean\_shape\_points()
