ITK: 无法创建 IO 对象
ITK: Could not create IO object
我正在尝试计算图像的梯度。我在给定的示例图像上尝试了 this code (Gourds6.png)。
我使用 cmake .
创建了 CMakeFile,然后 make
。一切正常,可执行文件已创建。现在,当我 运行 使用命令 ./computeGradient Gourds6.png out.png 1.5
的代码时,它会抱怨:
Error:
itk::ImageFileWriterException (0x1446b40)
Location: "void itk::ImageFileWriter<TInputImage>::Write() [with TInputImage = itk::Image<float, 2u>]"
File: /usr/local/include/ITK-4.3/itkImageFileWriter.hxx
Line: 152
Description: Could not create IO object for file out.png
Tried to create one of the following:
You probably failed to set a file suffix, or
set the suffix to an unsupported type.
我没有对此代码进行任何更改。它应该工作。我不知道它有什么问题:(你有什么想法吗?
此外,为什么我们不需要更新 reader 来读取图像?为什么我们只更新作家?
感谢您的帮助!
this example of ITK中输出文件的像素类型是float
。并写入 float
的图像,因为 PNG 图像是不可能的。
中给出了支持的文件格式和相应数据类型的列表
要保存这张 float
的图像,以下是预期有效的格式:
- 分析 (.img)
- DICOM(.dic:在我的电脑上失败)
- GIPL (.gipl)
- 元图像 (mhd) (out.mhd+out.raw)
- Nrrd (.nhdr, .nrrd)
- 刺激 (.spr)
- VTK (.vtk)
VTK文件格式效果很好,可以用paraview软件打开
要使用 PNG 格式,图像应转换为 unsigned char
类型。它可能由 CastImageFilter()
. See this example. Another solution is to use the RescaleIntensityImageFilter()
. See this example.
执行
This question and its answer(恰好是我的)解释了如何将 float
图像类型转换为 ùnsigned char` 图像类型并将其保存为 PNG。
typedef itk::RescaleIntensityImageFilter< FloatImageType, UCharImageType > RescaleFilterType;
RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
rescaleFilter ->SetInput(importFilter->GetOutput());
rescaleFilter->SetOutputMinimum(0);
rescaleFilter->SetOutputMaximum(255);
typedef itk::ImageFileWriter< UCharImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( "output.png" );
writer->SetInput(rescaleFilter->GetOutput() );
writer->Update();
最后,你的最后一个问题:为什么我们只更新作者?当 writer 更新时,它会首先检查它的条目是否是最新的。如果不是这样,它将调用filter->Update()
,依此类推。
我正在尝试计算图像的梯度。我在给定的示例图像上尝试了 this code (Gourds6.png)。
我使用 cmake .
创建了 CMakeFile,然后 make
。一切正常,可执行文件已创建。现在,当我 运行 使用命令 ./computeGradient Gourds6.png out.png 1.5
的代码时,它会抱怨:
Error:
itk::ImageFileWriterException (0x1446b40)
Location: "void itk::ImageFileWriter<TInputImage>::Write() [with TInputImage = itk::Image<float, 2u>]"
File: /usr/local/include/ITK-4.3/itkImageFileWriter.hxx
Line: 152
Description: Could not create IO object for file out.png
Tried to create one of the following:
You probably failed to set a file suffix, or
set the suffix to an unsupported type.
我没有对此代码进行任何更改。它应该工作。我不知道它有什么问题:(你有什么想法吗?
此外,为什么我们不需要更新 reader 来读取图像?为什么我们只更新作家?
感谢您的帮助!
this example of ITK中输出文件的像素类型是float
。并写入 float
的图像,因为 PNG 图像是不可能的。
要保存这张 float
的图像,以下是预期有效的格式:
- 分析 (.img)
- DICOM(.dic:在我的电脑上失败)
- GIPL (.gipl)
- 元图像 (mhd) (out.mhd+out.raw)
- Nrrd (.nhdr, .nrrd)
- 刺激 (.spr)
- VTK (.vtk)
VTK文件格式效果很好,可以用paraview软件打开
要使用 PNG 格式,图像应转换为 unsigned char
类型。它可能由 CastImageFilter()
. See this example. Another solution is to use the RescaleIntensityImageFilter()
. See this example.
This question and its answer(恰好是我的)解释了如何将 float
图像类型转换为 ùnsigned char` 图像类型并将其保存为 PNG。
typedef itk::RescaleIntensityImageFilter< FloatImageType, UCharImageType > RescaleFilterType;
RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
rescaleFilter ->SetInput(importFilter->GetOutput());
rescaleFilter->SetOutputMinimum(0);
rescaleFilter->SetOutputMaximum(255);
typedef itk::ImageFileWriter< UCharImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( "output.png" );
writer->SetInput(rescaleFilter->GetOutput() );
writer->Update();
最后,你的最后一个问题:为什么我们只更新作者?当 writer 更新时,它会首先检查它的条目是否是最新的。如果不是这样,它将调用filter->Update()
,依此类推。