Running Slicer without GUI?

Yes here they are. I tried the method in the script repository and also a second attempt from here:Fastest way to load DICOM - #2 by lassoan

slicer_load_scans_debug.py

dicomDataDir = 'path/to/dicoms'

loadedNodeIDs = []

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))

Command

xvfb-run -a Slicer-4.11.20210226-linux-amd64/Slicer --no-splash --no-main-window --python-script 'startup/slicer_load_scans_debug.py'

Output:


qSlicerSequencesModulePrivate::addToolBar: no main window is available, toolbar is not added
Switching to temporary DICOM database: /tmp/Slicer-neureal2020/20211107_173523_TempDICOMDatabase
TagCacheDatabase adding table
Patient ID is empty, using studyInstanceUID (#########) as patient ID # repeats x169
"DICOM indexer has successfully inserted 169 files [0.14s]"
"DICOM indexer has successfully processed 169 files [0.18s]"
Patient ID is empty, using studyInstanceUID (#########) as patient ID #repeats x169
"DICOM indexer has updated display fields for 169 files [0.07s]"
Loading with imageIOName: GDCM
vtkITKArchetypeImageSeriesReader::ExecuteInformation: Archetype file /tmp/Slicer-user/scan_name_TempDICOMDatabase/path/to/dicoms/FILE12 does not exist.
Algorithm vtkITKArchetypeImageSeriesScalarReader(0x5826580) returned failure for request: vtkInformation (0x58278e0)
  Debug: Off
  Modified Time: 128579
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_INFORMATION
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0
Could not read scalar volume using GDCM approach.  Error is: FileNotFoundError
Loading with imageIOName: DCMTK
vtkITKArchetypeImageSeriesReader::ExecuteInformation: Archetype file Archetype file /tmp/Slicer-user/scan_name_TempDICOMDatabase/path/to/dicoms/FILE12 does not exist.
Algorithm vtkITKArchetypeImageSeriesScalarReader(0x38bdd60) returned failure for request: vtkInformation (0x5a45430)
  Debug: Off
  Modified Time: 128662
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_INFORMATION
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0
Could not read scalar volume using DCMTK approach.  Error is: FileNotFoundError

This was the second attempt:

slicer_load_scans_debug.py

import DICOMLib
import re
DICOMLib.importDicom(dicomDataDir)
dicomFiles = slicer.util.getFilesInDirectory(dicomDataDir)
loadablesByPlugin, loadEnabled = DICOMLib.getLoadablesFromFileLists([dicomFiles])
loadedNodeIDs = DICOMLib.loadLoadables(loadablesByPlugin)
for loadedNodeID in loadedNodeIDs:
    node = slicer.mrmlScene.GetNodeByID(loadedNodeID)
    safeFileName = re.sub(r'(?u)[^-\w.]', '', node.GetName().strip().replace(' ', '_'))
    slicer.util.saveNode(node, '{0}/{1}.nrrd'.format(outputDir, safeFileName))

Output

qSlicerSequencesModulePrivate::addToolBar: no main window is available, toolbar is not added
Patient ID is empty, using studyInstanceUID (#########) as patient ID # repeats x169
"DICOM indexer has successfully inserted 169 files [0.14s]"
"DICOM indexer has successfully processed 169 files [0.18s]"
Patient ID is empty, using studyInstanceUID (#########) as patient ID #repeats x169
"DICOM indexer has updated display fields for 169 files [0.07s]"
Loading with imageIOName: GDCM
Could not load  "/tmp/Slicer-user/scan_name_TempDICOMDatabase/path/to/dicoms/FILE12" 
DCMTK says:  No such file or directory
File /tmp/Slicer-user/scan_name_TempDICOMDatabase/path/to/dicoms/FILE12 could not be initialized.
No geometry information available for DICOM data, skipping corner calculations

It goes on to give me errors related to saving the .nrrd. I could not reproduce the database not found error, apologies.