ITK imageSeriesReader无法读取dicom系列

时间:2015-05-10 16:50:06

标签: c++ input dicom series itk

使用ITK读取DICOM图像系列时遇到一些问题。 请查看从itk示例中截获的代码。

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;
}

程序可以正确输出dicom系列名称。

但是当执行reader-&gt; Update()时,它会说:

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].

为什么所需的图像尺寸必须为[256,1]?

图片系列可以从http://www.vtk.org/Wiki/File:VTK_Examples_StandardFormats_Input_DicomTestImages.zip下载 在演示程序中发生错误时无望。

3 个答案:

答案 0 :(得分:0)

我得到了完全相同的错误。 但是我的图像具有相同的尺寸,如果我逐一阅读它,我没有错误...只是使用itk.ImageSeriesReader似乎擦除了每个文件的最后一个维度......

有效:

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

没有:

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

并提供错误:

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

(抱歉这是python代码)

答案 1 :(得分:0)

尝试使用“ const unsigned int Dimension = 3;”而是“ const unsigned int Dimension = 2;”

对我有用。

答案 2 :(得分:-1)

您应该尝试使用reader->UpdateLargestPossibleRegion();代替reader->Update();