1
votes

I have some problems in using ITK to read DICOM images series. Please look at the code which is intercepted from itk examples.

http://www.itk.org/Doxygen47/html/Examples_2IO_2DicomSeriesReadSeriesWrite_8cxx-example.html

#include "itkGDCMImageIO.h"
#include "itkGDCMSeriesFileNames.h"
#include "itkImageSeriesReader.h"
#include "itkImageSeriesWriter.h"
#include <vector>
#include "itksys/SystemTools.hxx"

int main(  )
{

  typedef int    PixelType;
  const unsigned int      Dimension = 2;

  typedef itk::Image< PixelType, Dimension >      ImageType;
  typedef itk::ImageSeriesReader< ImageType >     ReaderType;

  typedef itk::GDCMImageIO                        ImageIOType;
  typedef itk::GDCMSeriesFileNames                NamesGeneratorType;

  ImageIOType::Pointer gdcmIO = ImageIOType::New();
  NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
  namesGenerator->SetInputDirectory("/home/co/imageData/DicomTestImages");


  const ReaderType::FileNamesContainer & filenames = namesGenerator->GetInputFileNames();
  unsigned int numberOfFilenames =  filenames.size();
  std::cout << numberOfFilenames << std::endl;
  for(unsigned int fni = 0; fni<numberOfFilenames; fni++)
    {
    std::cout << "filename # " << fni << " = ";
    std::cout << filenames[fni] << std::endl;
    }


  ReaderType::Pointer reader = ReaderType::New();
  reader->SetImageIO( gdcmIO );
  reader->SetFileNames( filenames );

  reader->Update();

  return 0;
}

The program can output the dicom series names correctly.

But when executing reader->Update(),it says:

terminate called after throwing an instanceof'itk::ExceptionObject'what():  
/usr/local/include/ITK4.7/itkImageSeriesReader.hxx:371:
itk::ERROR: ImageSeriesReader(0x99a9af8): Size mismatch! The size of  /home/co/imageData/DicomTestImages/MRI.000 is [256, 256] and does not match the required size [256, 1].

Why the image size required must be [256,1]?

The image series can be downloaded from http://www.vtk.org/Wiki/File:VTK_Examples_StandardFormats_Input_DicomTestImages.zip It is hopeless when error happens in the demo-program.

3
What ITK Version do you use? - JohnnyQ
The error says that the first file that was read had size = [ 256,1] - so it's expecting all the slices to have that size. Can you check the folder again? Sorry I can not try the code now, but the data file you linked has different filenames - lib

3 Answers

0
votes

i got the exact same error. BUT my images have all the same dimension, I got no errors if I read them one by one ... just using itk.ImageSeriesReader seems to erase the last dimension of each files...

that works:

import itk, numpy
slices = sorted(filenames)
    for idx, file in enumerate(slices):
        volume.append(itk.GetArrayFromImage(itk.imread(file)))
return numpy.asarray(volume)

that doesn't:

import itk, numpy
slices = sorted(filenames)
reader = itk.ImageSeriesReader.New(FileNames=slices)
volume = reader.GetOutput()

and provide the error:

itk::ERROR: ImageSeriesReader(0x14e81e2d0): Size mismatch! The size of  ./A23780DIATD/A23780DIATD_rec/A23780DIATD__rec0029.bmp is [864, 824] and does not match the required size [864, 1] from file ./A23780DIATD/A23780DIATD_rec/A23780DIATD__rec0029.bmp

(sorry this is python code)

0
votes

Try using "const unsigned int Dimension = 3;" instead "const unsigned int Dimension = 2;"

It works for me.

-1
votes

You should try to use reader->UpdateLargestPossibleRegion(); instead of reader->Update();