[Insight-users] Getting Origin using GDCMImageIO and ImageSeriesReader

sharath kumar sargerocks at gmail.com
Sat Nov 10 01:41:02 EST 2012


I am trying to read a 4D cardiac MR volume from a set of .dcm files
using the ImageSeriesReader and GDCMImageIO. Since cardiac MRI has
about 8-14 slices and about 20 phases, there are about 150-200 images.
I need to get the origin of each slice separately. But when I read all
the images using ImageSeriesReader, and the GDCMImageIO to read the
origin DICOM tag, I end up with just one value for the origin (not
sure which slice this comes from). Please can anyone let me know how I
can read the origin of each slice in the volume separately. My code
looks as shown below. I would appreciate any kind of help on this
issue. Thanks.

void ImageVolume::ReadImageDir(const QString& dir)
{
    typedef itk::ImageSeriesReader< Image3DType > SeriesReader3DType;
    typedef itk::GDCMImageIO ImageIOType;
    typedef itk::GDCMSeriesFileNames NamesGeneratorType;
    NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
    nameGenerator->SetUseSeriesDetails(true);
    nameGenerator->AddSeriesRestriction("0008|0021");
    nameGenerator->SetDirectory(dir.toStdString().c_str());

    try
    {
        typedef std::vector<std::string> SeriesIdContainer;
        const SeriesIdContainer& seriesUID = nameGenerator->GetSeriesUIDs();

        SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
        while(seriesItr != seriesUID.end())
        {
            std::string seriesIdentifier = seriesItr->c_str();
            std::vector<std::string> fileNames;
            fileNames = nameGenerator->GetFileNames(seriesIdentifier);

            SeriesReader3DType::Pointer reader = SeriesReader3DType::New();
            ImageIOType::Pointer dicomIO = ImageIOType::New();
            reader->SetImageIO(dicomIO);
            reader->SetFileNames(fileNames);
            try
            {
                reader->Update();
            }
            catch (itk::ExceptionObject &ex)
            {
                throw;
            }
            Image3DType::Pointer ptr = reader->GetOutput();
            _volumeSeries.push_back(ptr);
            ++seriesItr;

            std::string origin;
            const std::string ORIGIN_TAG("0020|0032");
            dicomIO->GetValueFromTag(ORIGIN_TAG, origin);
            std::cout << "Origin = " << origin << std::endl;
        }
    }
    catch (itk::ExceptionObject &ex)
    {
        throw;
    }
}


More information about the Insight-users mailing list