[Insight-users] ITK 4.1 ImageIOFactory Could not create IO Object

Sebastian Losch seb.losch at googlemail.com
Tue May 22 04:35:29 EDT 2012


Hi!

I am having problems getting the ImageFileReader and ImageFileWriter to
work. I just want to read a PNG File, apply a filter and write it back to
the harddrive. I found out that there is a problem in 4.1 with the
ImageIOFactory registration, so i register the PNGFactory manually. The
.png file is in the same folder as the executable. Here is my Code:

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkCannyEdgeDetectionImageFilter.h"
#include "itkObjectFactoryBase.h"
#include "itkPNGImageIOFactory.h"

int main(int argc, char *argv[])
{
itk::ObjectFactoryBase::RegisterFactory(itk::PNGImageIOFactory::New());


double variance = 2.0;
double upperThreshold = 0.0;
double lowerThreshold = 0.0;

typedef itk::Image<double, 2>  DoubleImageType;

typedef itk::ImageFileReader<DoubleImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName("input.png");

typedef itk::CannyEdgeDetectionImageFilter <DoubleImageType,
DoubleImageType>
CannyEdgeDetectionImageFilterType;

CannyEdgeDetectionImageFilterType::Pointer cannyFilter =
CannyEdgeDetectionImageFilterType::New();
cannyFilter->SetInput(reader->GetOutput());
cannyFilter->SetVariance( variance );
cannyFilter->SetUpperThreshold( upperThreshold );
cannyFilter->SetLowerThreshold( lowerThreshold );

typedef itk::ImageFileWriter<DoubleImageType> WriterType;
WriterType::Pointer writer = WriterType::New();

writer->SetFileName("test.png");
writer->SetInput(cannyFilter->GetOutput());

try {
writer->Update();
} catch (itk::ExceptionObject &e) {
std::cerr << e << std::endl;
}

std::cout << "ENDE" << std::endl;
}

and this is the error:

itk::ImageFileReaderException (0059E4A8)
Location: "void __thiscall itk::ImageFileReader<class
itk::Image<double,2>,class itk::DefaultConvertPixelTraits<double>
>::GenerateOutputInformation(void)"
File: c:\libs\itk\include\itk-4.1\itkimagefilereader.hxx
Line: 143
Description:  Could not create IO object for file input.png
  Tried to create one of the following:
    PNGImageIO
  You probably failed to set a file suffix, or
    set the suffix to an unsupported type.


What am i doing wrong?

Thanks in advance, Sebastian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120522/df610528/attachment.htm>


More information about the Insight-users mailing list