Creates Cylinder in Center of a segment for volume calculation

Due to the processing difficulty i thought of a work around like in the video attached for my purpose. The script @Juicy @lassoan help with do the trick by automating the process but i takes lot of time.

The way i think of working this out was,

  1. first segment the implant
  2. Exported it to Blender as stl.
  3. Get the center of object and made a cylinder with know dimensions.

these cylinder were the size of what we were trying to grow which took lot of time.

  1. reimported them to Slicer

  2. Calculate the volume

  3. to threshold the bone only, used thresholding only insde that segment.

  4. This is superfast but I just want to know is this has any effect on calculations compare to growing the margins ? Is this a correct method or completely wrong way of going about this ?

  1. The entire process depend on accurate alignment of the first cylinder and Bledner came in becuase i could not deduce how to get the center of segment with GetMesh().GetCenter() and also i think it calculates the center of the bounding box which might not be what i want here.

  2. When i did get the some kind of values for center and when i try to create the cylinder it was embarrassingly out of sync. :joy:

  1. Provided the method is accurate, is it possible to get the center of my segment and then create a cylinder along the long axis or is there a way of putting a fiducial to the center of the segment and then i can just draw a circle from that ?

I cant really comment on the validity of growing the segment vs placing a cylinder around the segment as I dont know the project.

Looks like there are some great new features in Segment Statistics. You could find the centroid of the segment, place a cylinder model at the centroid and then align it with the principal axes of the segment (also found with segment statistics).

You could probably write a script which calls the logic of segment statistics to find centroid and principal axes and then places a vtk cylinder at the centroid and aligns it using a transform or perhaps you can specify angle on placement from the cration options for a vtk cylinder?


Dear @Juicy,

Thanks you for the help. I was not aware of the new features in the segment statistics and it is extremely useful. Our problem for now was solved with the new update on the margin growing algorithm thanks to Prof @lassoan and @Sunderlandkyl . Now the Margin growing is super fast !!! So we will not have to do work around on this now. But I think the repetition script will be useful to many, some where along the way.

The Cylinder problem was also to work around our original problem but it is a common way that others have done analysis too. So i would like to get to know how to do that properly even though it is not needed for now.

From the script repository i get it,

implant = vtk.vtkCylinderSource()
implant.SetCenter(3.0603, -0.409605, 14.2942)

implantNode = slicer.modules.models.logic().AddModel(implant.GetOutputPort())

So as you said it is only a question of orienting/transforming the object axis but i could not see any things that sets the objects axis. So i guess it is under the transformation ?
but i do not understand this step on how to set the transformation on the object from the script at all !!!
If someone could help much appreciated.

You can find examples of how to set transforms in Transforms module documentation and in script repository.

1 Like