C++ 使用ITK写入时扭曲的DICOM图像

C++ 使用ITK写入时扭曲的DICOM图像,c++,image,image-processing,itk,writing,C++,Image,Image Processing,Itk,Writing,我正试图在一个大型ITK项目中编写一系列dicom图像。这些图像是应用大量不同过滤器后的最终图像。我正在使用VTK的图像平面小部件来显示我的图像 我写dicom文件有问题。代码确实写了,但图像根本不正确。如果我在RadiantViewer或imageJ中查看它们,它们会显示为一些扭曲的图像(见图)。(我试图更正窗口级别设置,看看这是否有问题) 图:失真的dicom图像 在以前使用Microsoft Visual Studio 2010 professional进行的安装中,它正在工作。但是,我

我正试图在一个大型ITK项目中编写一系列dicom图像。这些图像是应用大量不同过滤器后的最终图像。我正在使用VTK的图像平面小部件来显示我的图像

我写dicom文件有问题。代码确实写了,但图像根本不正确。如果我在RadiantViewer或imageJ中查看它们,它们会显示为一些扭曲的图像(见图)。(我试图更正窗口级别设置,看看这是否有问题)

图:失真的dicom图像

在以前使用Microsoft Visual Studio 2010 professional进行的安装中,它正在工作。但是,我使用的是Microsoft Visual Studio 2015社区版。代码的其余部分似乎正在工作,包括在VTK的Image Plane小部件中查看结果。但是,导出的文件不正确。 我通读了关于在ITK窗口中编写dicom系列的部分,但我并没有真正看到我做错了什么

在应用过滤器的最后一步中,我使用指针阈值2将图像数据转换为8bit,作为三维无符号字符(用于VTK中的进一步网格划分)

接下来,我定义输出目录,将thresholder2指向的数据导出到该目录,将用于写入图像的类型设置为二维非单字符(因为我想要的是dicom系列,而不是卷),获取输出并将其传递到ImageIO,获取生成的名称并保存

有人知道我做错了什么吗

任何帮助都将不胜感激

typedef float             OutputPixelType; 
const unsigned int        Dimension = 3;
typedef itk::Image< OutputPixelType, Dimension >   OutputImageType;
typedef itk::Image< unsigned char,   Dimension >   CharImageType;
    typedef itk::BinaryThresholdImageFilter<OutputImageType, CharImageType > ThresholdingFilterType;
    ThresholdingFilterType::Pointer thresholder2 = ThresholdingFilterType::New();

    thresholder2->SetInput(geodesicActiveContour->GetOutput() );
    thresholder2->SetLowerThreshold(-1000); 
    thresholder2->SetUpperThreshold(0);
    thresholder2->SetOutsideValue( 0 ); 
    thresholder2->SetInsideValue( 255 ); 
    thresholder2->Update( );

const char * outputDirectory = "C:/ITK-VTK/dicoms_to_test_second_patient/results";
itksys::SystemTools::MakeDirectory( outputDirectory );

typedef itk::Image<unsigned char, 2 > WriteImageType;
typedef itk::ImageSeriesWriter<CharImageType,WriteImageType > SeriesWriterType;


SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
seriesWriter->SetInput(thresholder2->GetOutput() );
seriesWriter->SetImageIO(dicomIO);

nameGenerator->SetOutputDirectory( outputDirectory );
seriesWriter->SetFileNames( nameGenerator->GetOutputFileNames() );
seriesWriter->SetMetaDataDictionaryArray(reader->GetMetaDataDictionaryArray());

try
{
seriesWriter->Update();
}
catch( itk::ExceptionObject & excp )
{
std::cerr << "Exception thrown while writing the series " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
typedef float OutputPixelType;
常量无符号整数维=3;
typedef itk::ImageOutputImageType;
typedef itk::ImageCharImageType;
typedef itk::BinarySthresholdImageFilter ThresholdingFilterType;
ThresholdingFilterType::Pointer thresholder2=ThresholdingFilterType::New();
thresholder2->SetInput(geodesicActiveContour->GetOutput());
阈值2->SetLowerThreshold(-1000);
阈值2->设置阈值(0);
阈值2->设置外部值(0);
阈值2->SetInsideValue(255);
thresholder2->Update();
const char*outputDirectory=“C:/ITK-VTK/dicoms\U to\U test\U second\U patient/results”;
itksys::SystemTools::MakeDirectory(outputDirectory);
typedef itk::Image WriteImageType;
typedef itk::ImageSeriesWriter系列WriterType;
SeriesWriterType::指针seriesWriter=SeriesWriterType::New();
seriesWriter->SetInput(阈值2->GetOutput());
seriesWriter->SetImageIO(dicomIO);
名称生成器->设置输出目录(输出目录);
seriesWriter->SetFileNames(nameGenerator->GetOutputFileNames());
seriesWriter->setMetadataDictionaryRay(reader->getMetadataDictionaryRay());
尝试
{
seriesWriter->Update();
}
捕获(itk::例外对象和excp)
{
标准:cerr