使用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-> 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下载
当演示程序中发生错误时,这是没有希望的。
最佳答案
我得到了完全一样的错误。
但是我的图像具有相同的尺寸,如果我一一读取它们,我不会出错...仅使用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代码)
关于c++ - ITK imageSeriesReader无法读取dicom系列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30154022/