I’m relatively new to both Python and 3D Slicer, but I am trying to calculate the surface area of the human placenta through 3D Slicer and then convert this into Python code for an automatic calculation of the placental surface area. I have a data set of NIfTI files of already segmented placentas, but I’m unsure how to get the surface area through 3D Slicer. Any help would be appreciated. Thank you.
I’ve rendered the 3D volume in the top right corner through Volume Rendering
I’ve added my segment under Segment Editor
I’ve applied only the ‘Closed Surface Statistics’ option under Segment Statistics after choosing my segment as my input, but I am not given the surface area for some reason - this is where I’m currently stuck
You need to have closed surface representation to compute “Closed surface statistics”. You can compute it by clicking the “Show 3D” button in Segment Editor module or by choosing “Create closed surface representation” in the right-click menu in Data module.
I would not recommend using Volume Rendering module for 3D rendering of a segmentation because it does not do an accurate reconstruction of the original smooth, continuous surface, but it just shows each voxel as a cube. Instead, load the file as a segmentation (choose Segmentation in “Add data” window’s “Description” column) and then create the closed surface representation to see it in 3D.
My goal is to write a Python code that can automatically calculate the surface area of a large dataset of placentas from 3D MRI images. With 3D Slicer, I was aiming to integrate it into my python code and get the surface area information directly that way
That sounds very easily doable. Probably the simplest is to run all your Python code in Slicer’s Python environment. You can automate everything that you did in Slicer GUI using Python scripting and you can add any additional processing in the same script. This PerkLab Bootcamp Slicer Programming tutorial is a good starting point, you can find many examples in the script repository and if you don’t find any answer then you can ask on this forum.
Thank you for the resources. I looked through the steps in the PerkLab tutorial on slides 36-49 and tried slides 36-43 myself before I got stuck. I’m wondering, is the .py file in 3D Slicer what I need to focus on to help me get Python code to calculate surface area? Is it something that automatically updates after I run 3D Slicer and get the surface area that way, or do I need to manually update the .py file? I want first to understand how I need to go about this, as I’m still somewhat new to Python
For this task you don’t need to develop a new Slicer module, just write a short code snippet that uses existing modules. However, the exercises, examples, links to resources, etc. are all applicable to a simple Python script the same way as to a Slicer module.
Since you will not develop a new Slicer module, you’ll just write a Python script and start it using Slicer.exe --python-script /path/to/myscript.py. If you modify the script, save it, and launch it with this command then the modified script will run.
From the first link, “slicer.util.loadSegmentation” is not working on PyCharm for me, I have imported ‘slicer,’ but I can’t find anything on ‘util’
I tried ‘pip install util’ in the command window, but I was getting another error with util:
ERROR: Could not find a version that satisfies the requirement util (from versions: none) ERROR: No matching distribution found for util
Would you happen to know if there’s an alternative to this line of code from the script repository or how to find the download for util? I have looked on pypi.org, but I don’t know which one is the correct one.