本文介绍了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?

我感谢您的帮助!

推荐答案

。请参阅此。另一个解决方案是使用。请参阅此。

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对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 00:15