Operating system: win10
Slicer version: 4.10.2
Expected behavior:
Actual behavior:
Hi,
I have two folders containing .IMA files. I want to load them automatically into slicer using the folder paths and then perform registration between them.
So, I need to do first
# Load Volume
[ success,movingVolumeNode ] = slicer.util.loadVolume(Movinfilename,returnNode=True)
[ success, fixedVolumeNode] = slicer.util.loadVolume(Fixedfilename,returnNode=True)
And then
logic = SomeRegistrationLogic()
…
logic.registerVolumes(fixedVolumeNode, movingVolumeNode, outputVolumeNode)
But slicer.util.loadVolume takes a file not a directory. So my question is how can I import each of these directories using a python script and get them as volume node ?
By .IMA files I guess you mean dicom? You can try some of the methods in DICOMUtils. Also here’s a script that takes a directory of dicoms on the command line and makes volumes out of them. I haven’t tried this in a while and it may need some tweaking for the current Slicer.
Hi @pieper
The “db” error is fixed.
It would be db =slicer.app.dicomDatabase().
However it runs successfully and execute "No scalar volumes parsed from the input DICOM dataset! Aborting."
Meaning no nodes!! Do you have any idea?
However it shows that it is imported in the slicer. But needs to be loaded in the GUI.
@pieper
I got another example from here.
dicomDataDir = “c:/my/folder/with/dicom-files” # input folder with DICOM files
loadedNodeIDs = [] # this list will contain the list of all loaded node IDs
from DICOMLib import DICOMUtils
with DICOMUtils.TemporaryDICOMDatabase() as db:
DICOMUtils.importDicom(dicomDataDir, db)
patientUIDs = db.patients()
for patientUID in patientUIDs:
loadedNodeIDs.extend(DICOMUtils.loadPatientByUID(patientUID))
But before I can check for volume node, it throws error:
loadedNodeIDs.extend(DICOMUtils.loadPatientByUID(patientUID))
TypeError: ‘bool’ object is not iterable
We recently reworked the DICOM browser. You need to use latest Slicer Preview Release for this last example (few days old release should be still OK, several weeks old may work differently).
Hi @lassoan,
Do you have any suggestion to fix this code (slicer 4.10.2) or another working example to load dicoms from folder and access as volume node using python scripting ?
Slicer-4.10 will soon be retired and Slicer-4.11 will be promoted to be the new stable release, so I would recommend to use most recent Slicer-4.11 version.
@lassoan@pieper
So I found a simpler way. Simple providing the a single file of the folder in below method do the task. It loads all the files automatically.
slicer.util.loadVolume(‘single_file_of_folder’) .
Can you please tell me How can I set this loaded volume node as the fixed or moved volume from command line to perform landmark registration? I do not want use the gui.
Thanks
Hi @pieper,
I followed the exact example and it got solved
However, It is important that in my case I had to update the transform node from python script.