I am trying to generate transformations and resample scalar volumes in Slicer programmatically with Python. And have two questions:
I am unable to find a scripted module corresponding to ‘Resample Scalar/Vector/DWI Volume’ on GitHub. The steps I need to implement are - set input volume, create new output volume as, set the transform, reference volume, and ensure linear interpolation. Can someone please help me to get started?
I am working in a Jupyter Notebook with Slicer kernel. As an attempt at automation, I am trying to pause my run, prompt user to add fiducials to the image on Slicer, and then continue running the script.
This is not working as it just freezes my jupyter notebook and fails the kernel. Any suggestions on how I could implement this?
It is implemented in C++, see source code here. You can call CLI module from Python as described here.
Notebooks are great for development and batch processing but if you want to implement interactive workflows for end users then scripted modules is a much more suitable option. You can create a simple GUI that contains a node selector to place markups points, maybe some more GUI widgets to set parameters, etc. Script in your notebook will become the module logic. I would recommend the PerkLab bootcamp Slicer programming tutorial to learn how to turn your script into a Slicer module.
Thank you for the quick response! I tried following the example you provided for the 1st problem and I still have an error. I have an input volume labeled ‘Axial’ and a transform ‘ACPC Transform’ already created in Slicer.
I don’t understand why there is no data assigned to “Input Volume” when I clearly have.
Just checked the source of resampleModule (link above) and it shows that the CLI call needs the following parameter strings: “inputVolume”, “outputVolume”, “referenceVolume”, “transformationFile” and “interpolationType” .
Thank you, yes. I also found the same thing after your comment about verifying the parameter names. Unfortunately, I have the same error still. I tried pulling the volumes using “slicer.mrmlScene.GetFirstNodeByClass” like you mentioned, instead of “slicer.util.getNode” just to see if it would make a difference. I still have the same error.
As the error message tells, you provided a collection of nodes, instead of a volume node. This is because the method you used provides a collection of nodes. I would recommend to use slicer.util helper functions to get nodes from the scene because they are easier to use in Python.
Thank you so much Rudolf and Andras! I was able to follow your advice and pass the right datatype. I visualized the volume resampled manually using Slicer and the one I did with Python - They match perfectly.