Mean Shape Calculation

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}")

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:

E.g. Analyze.get_mean_shape_points()