I am fairly new to 3d slicer but I am trying to figure out how and I automate or speed up the process of getting a histogram of voxel data from a segmented section. I have been able to do this for one segment at a time through 3d slicer’s own python interactor using the code
at Script repository — 3D Slicer documentation. But I want to be able to make a python function that loops through files in a directory and spits out either data or a histogram for each one. If anyone has any ideas about how to do this or where I should look to learn more about this that would be much appreciated.
You can run the code snippet in a loop that iterates through files in a folder. You can find Python many tutorials on the web on how get filenames in a folder in Python.
Great! Thank you! And just to clarify, would I be looping through those files from within slicer 3d’s python interactor, or is it possible to do it from a third party code editor like pycharm or vscode?
You can do it from anywhere - interactively copy-pasting into Slicer’s Python console, running a Python script from the command line, in a Jupyter notebook. You can also use PyCharm or Visual Studio Code for development and interactive debugging.
The only unusual in Slicer’s Python environment is that most of the classes are instantiated by the Slicer application, therefore if you just set PythonSlicer.exe as your Python interpreter (instead of launching the Slicer application and attaching a Python debugger to it) then you’ll only have a small fraction of the features available.