ITK:无法创建IO对象 [英] ITK: Could not create IO object

查看:564
本文介绍了ITK:无法创建IO对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算图像的渐变。我尝试了这段代码给出的示例图片(Gourds6.png )。

I am trying to calculate the gradient of an image. I tried this code on the sample image given (Gourds6.png).

我使用 cmake。创建CMakeFiles,然后 make 。一切工作正常,并创建可执行文件。现在,当我使用命令 ./ computeGradient Gourds6.png out.png 1.5 运行代码时,它会抱怨:

I used cmake . to create the CMakeFiles and then make. Everything works fine and the executable file is created. Now when I run the code using command ./computeGradient Gourds6.png out.png 1.5, it complains that:

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.

我没有对此代码做任何更改。它应该工作。我不知道有什么问题:(你有什么想法吗?

I haven't done any change to this code. It should work. I don't know what is wrong with it :( Do you have any idea?

另外,为什么我们不需要更新读取器来读取图像?为什么我们只更新作者?

Also, why we don't need to update the reader to read the image? Why we only update the writer?

我感谢您的帮助!

推荐答案

此ITK示例中的输出文件的像素类型a>是 float ,并且不能将PNG图像作为 float 的图像。

The pixel type of the output file in this example of ITK is float. And write an image of float as a PNG image is not possible.

提供了支持的文件格式和相应数据类型的列表

A list of supported file format and corresponding data type is given on the wiki of ITK.

要保存 float 的图片,这里是预期的格式工作:

To save this image of float, here are formats that are expected to work :


  • 分析(.img)

  • DICOM )

  • GIPL(.gipl)

  • MetaImage(mhd)(out.mhd + out.raw)

  • Nrrd(.nhdr,.nrrd)

  • 刺激(.spr)

  • VTK(.vtk)

  • Analyze (.img)
  • DICOM (.dic : failed on my PC)
  • GIPL (.gipl)
  • MetaImage (mhd) (out.mhd+out.raw)
  • Nrrd (.nhdr, .nrrd)
  • Stimulate (.spr)
  • VTK (.vtk)

VTK文件格式很好,可以由paraview软件打开。

The VTK file format works well and may be opened by the paraview software.

使用PNG格式,则该映像应转换为 unsigned char 类型。它可以由 CastImageFilter() 。请参阅此示例。另一个解决方案是使用 RescaleIntensityImageFilter() 。请参阅此示例

To use a PNG format, the image should be casted to unsigned char type. It may be performed by the CastImageFilter(). See this example. Another solution is to use the RescaleIntensityImageFilter(). See this example.

此问题和它的答案(这恰好是我的)解释如何将 float 图像类型转换为ùnsignedchar`图像类型并将其另存为PNG。 p>

This question and its answer (which happens to be mine) explains how to convert a float image type to a ùnsigned char` image type and save it as 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();

最后,最后一个问题:为什么我们只更新作家?当写入器被更新时,它将首先检查它的条目是否是最新的。如果不是这样,它将调用 filter-> Update(),等等。

Finally, your last question : why we only update the writer ? As the writer is updated, it will fist check if its entries are up to date. If it is not the case, it will call filter->Update(), and so on.

这篇关于ITK:无法创建IO对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆