I have 4D dynamic susceptibility contrast (DSC) dicom images (T2* with contrast agent) to analyze.
I’ve noticed that I can convert NIFTI files to NRRD files, just by click “Save” in Slicer. However, I want to convert hundreds of NIFTI files to NRRD files, so I need to do it by command lines.
Could anyone please tell me how can I do it by command lines?
Thank you in advance!
All operations you perform on the GUI are accessible through Python scripting, too. Save/load functions are exposed using a convenient interface in slicer.util package. You can start a script directly from the command-line as described here.
Thank you so much.
However, I don’t understand why the code below is not working. Could you please tell me what’s the problem? (e.g. option, syntax, etc.)
1. I just want to load 35000671_DSC.nii.gz and save as a NRRD file with the same basename (i.e. save/load problem for a single file).
MRHead=slicer.util.loadVolume(“D:\Data\SNUH_glioma\35000671_DSC.nii.gz”, returnNode=True)
head = slicer.util.getNode(‘MRHead’)
slicer.util.saveNode(head, “D:\Data\SNUH_glioma\35000671_DSC.nrrd”)
exit()
2. Moreover, I can’t find how to load files from the folder containing all the NIFTI files (hundreds of enrolled patient’s MRI) and save as NRRD files with the same basename.
Could you please tell me how to deal with this multi-files case?
You can get filename from full path or get all files in a folder using standard Python commands. You can easily find answers on Google search and StackOverflow.
However, I think it’s not the problem of Python commands.
I think it’s because there’s no “slicer.py” on my Slicer folder.
I think I should “import slicer” or “import slicer.util” to use those functions such as loadVolume, getNode, and saveNode. But “import slicer” in python console makes an error saying there’s no module named ‘slicer’.
Moreover, I can’t find more specific usage of “slicer.util.loadVolume” from the link.
For example, does the argument “filename” mean full file path - which is I understood?
I did it on the Slicer Python interactor, then I’ve got errors like these.
Can anyone tell me where should I save my python file not to see the error msg saying “no modules named ‘slicer’”?
I can’t find “slicer.py” or “slicerrc.py” in Slicer folder.
Thank you in advance!
If you want to use Slicer from a Jupyter notebook, then you need to use the Slicer Jupyter kernel. See instructions here: https://github.com/Slicer/SlicerJupyter.
Within Slicer’s Python interactor, slicer.util.loadVolume works well for me. Could you try to load a different image (e.g., download a Slicer sample data set, save to disk, and try to load that). Use stable or latest nightly version of Slicer. If you have any problems then attach the full application log (menu: Help / Report a bug).
I saved my slicer_test.py file in /bin/Python/slicer, where util.py in which loadVolume() function is contained.
However, running “python slicer_test.py” in command line gives me below error msg.
I tried to find “slicer.py” to import slicer module, which I couldn’t find at all.
2. Can I use “slicer.util.loadVolume → slicer.util.getNode → saveNode” functions in a row to convert NIFTI files in NRRD files?
However, above code makes an error.
I think I don’t understand what the “Node” is.
Do I have to use “loadNodeFromFile” function instead?
However, I don’t understand the argument “filetype”, which is not specific in the slicer package usage link.
Could you please give me more specific answer?
Thank you in advance!
It does not matter where you put your .py file. However, it is important to run it using Slicer.exe and not using Python.exe. Some features work with PythonSlicer.exe, too.
You can load volume using slicer.util.loadVolume(‘my filename.nrrd’)
However, I’ve noticed I have to load 4D DSC images, which cannot be done by util.loadVolume() function.
Should I use MultiVolumeImporter then?
However, I can’t find any function by that name on the link you posted. Please let me know what function should I use to load 4D DSC images in Python script?
So sorry to bother you.
Thank you so much!
Hi, Is it possible to convert 4D dicom images to a single nrrd file using the slicer/python command line? I want to loop over a collection of 4d data and convert each to nrrd or nifti for analysis.
I tried slicer.util.LoadVolume but am trying to split the data across the acquisition time. Is there an equivalent multivolumeimporter python call ?
slicer.util.LoadVolume supports very basic DICOM image import, but it is generally not recommended for loading DICOM data. It cannot load 4D data sets.