ITK imageSeriesReader无法读取dicom系列

时间:2021-08-15 10:07:10

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

我在使用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;
}

The program can output the dicom series names correctly.

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

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

但是当执行reader-> 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].

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

为什么所需的图像大小必须是[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.

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

3 个解决方案

#1


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

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

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)

(对不起,这是python代码)

#2


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

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

It works for me.

这个对我有用。

#3


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

你应该尝试使用reader-> UpdateLargestPossibleRegion();而不是reader-> Update();

#1


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

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

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)

(对不起,这是python代码)

#2


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

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

It works for me.

这个对我有用。

#3


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

你应该尝试使用reader-> UpdateLargestPossibleRegion();而不是reader-> Update();