# Parallelize itk::ImageSeriesReader (ITK 4.12)

**URL:** https://discourse.itk.org/t/parallelize-itk-imageseriesreader-itk-4-12/1745
**Category:** Engineering
**Tags:** dicom, gdcmio, threads, io
**Created:** [April 4, 2019, 1:38pm UTC](https://discourse.itk.org/t/parallelize-itk-imageseriesreader-itk-4-12/1745 "2019-04-04T13:38:49Z")
**Posts on this page:** 1
**Showing post:** 22

<div class="post-metadata">

### Author: ![svg](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@svg](https://discourse.itk.org/u/svg)
#### Post date: [April 17, 2019, 12:09pm UTC](https://discourse.itk.org/t/parallelize-itk-imageseriesreader-itk-4-12/1745/22 "2019-04-17T12:09:12Z")

</div>

Of course I did not create the reader globally.

I created a worker class, when spawned workers and gave them to a thread pool. Here is an example of how I did in QT:

```
class Worker : public QRunnable
{
private:
    QString mFilePath;

public:
    Worker(QString filePath)
    {
        mFilePath = filePath;

    }

    void run()
    {

            ReaderType::Pointer reader = ReaderType::New();

            typedef itk::GDCMImageIO ImageIOType;

            ImageIOType::Pointer dicomIO = ImageIOType::New();

            dicomIO->SetLoadPrivateTags(true);
            dicomIO->SetKeepOriginalUID(true);

            reader->SetImageIO( dicomIO );

            std::vector<std::string> fileNames;
            fileNames.push_back(mFilePath.toStdString());

            reader->SetFileNames( fileNames );

            try {
                reader->Update();
            }
            catch(itk::ExceptionObject& err) {
                qDebug() << mFilePath;
                qDebug() << err.GetDescription();
                return;
            }

            // Write file
            typedef itk::ImageSeriesWriter<FloatImageType4D, FloatImageType2D> SeriesWriterType;

            SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();

            seriesWriter->SetImageIO( reader->GetImageIO() );

            QString writePath = "/mnt/e357c8aa-9d7c-4668-bac6-fc6b286ff9f6/dicomfiles/output/";
            QString fileName = QFileInfo(QFile(mFilePath)).fileName();

            std::vector<std::string> outputFileNames;
            outputFileNames.push_back(QString(writePath + fileName).toStdString());
            seriesWriter->SetFileNames(outputFileNames);

            seriesWriter->SetInput(reader->GetOutput());

            try
            {
                seriesWriter->SetDebug(true);
                seriesWriter->Update();
            }
            catch( itk::ExceptionObject & excp )
            {
                qDebug() << writePath + fileName;
                qDebug() << excp.GetDescription();
                return;
            }
    }
};

```

Please note that this code has not been run, I just made it from my test code that had several modifications from my testing…

---

_[View the full topic](https://discourse.itk.org/t/parallelize-itk-imageseriesreader-itk-4-12/1745)._
