Parsing a DICOM directory recursively and reading all DICOM series from it is a time-consuming operation. I recently updated my application to parallelize this operation at the thread level as much as I can. But I found that ITK has limited support for such parallelization.
This is the most parallelized algorithm I could implement:
Step 1: The main thread parses the DICOM directory recursively and creates an itk::GDCMSeriesFileNames object.
Step 2: The main thread then calls GDCMSeriesFileNames::GetFileNames() for each series in the object, copies the file names to a vector of strings, and inserts the vector in a queue.
Step 3: Multiple worker threads consume the queue and read the series in parallel using thread-specific instances of itk::ImageSeriesReader objects.
Note, I did Step 1 in the main thread so as to create only one copy of the itk::GDCMSeriesFileNames object. Also, Step 2 had to be done in the main thread because the GetFileNames() routine isn’t thread safe.
Is there a more parallelized algorithm feasible with the current version of ITK?
If not, it will be great if we can update ITK such that Step 2 above, which is an expensive operation because it sorts the files, can be made thread safe so that it can also be executed in parallel for different series in worker threads. As far as I can see, it’s currently not thread safe only because GDCMSeriesFileNames::GetFileNames() routine stores the file names in a vector of strings, one of its private members:
Perhaps Step 2 can be made thread safe by overloading the GDCMSeriesFileNames::GetFileNames() function such that it returns the file names in a caller-provided reference to a vector of strings?
My suggestion assumes that GDCM, specifically the routines of the gdcm::SerieHelper class, are thread safe.