[Insight-users] Access pixel with iterator and write it in a file

Luis Ibanez luis.ibanez at kitware.com
Sun Sep 5 18:44:55 EDT 2004


Hi Bernhard,

The answer to your question is available in the FAQ

http://www.itk.org/Wiki/ITK_FAQ#I_got_the_message:_.22Could_not_create_IO_object_for_file.22


The message:

  "No ImageIO set, or  none could be created."

Usually means that the filename that you passed
to the ImageFileWriter did not match any of the
known fileformats in ITK.

Note that when writing, ITK uses the extension of
the filename in order to define the fileformat
to use.

You are passing ".raw" as file extension. RAW is not
a format. Using raw images is dangerous in medical
applications. Please use the MetaImage format that
will create a small text header with extension ".mhd"
and an associated raw file with extension ".raw"

That is, replace the line

       writer->SetFileName("test.raw");

with the line

       writer->SetFileName("test.mhd");




For a list of the fileformats and associated filename
extensions supported in ITK please look at the FAQ

http://www.itk.org/Wiki/ITK_FAQ#What_3D_file_formats_can_ITK_import_and_export.3F

Typical formats used in ITK, along with their extensions are

- DICOM       .dcm
- Analyze     .hdf
- MetaImage   .mhd
- GIPL        .gipl
- PNG         .png
- TIFF        .tiff
- JPEG        .jpg
- BMP         .bmp


You should also read the chapter on Reading and Writing
images, from the ITK Software Guide


    http://www.itk.org/ItkSoftwareGuide.pdf

Chapter 7, pdf-pages 219-239.



For recommendations on mechanisms for passing buffer data
in and out ITK filters and your application, you may
want to look at the Tutorial sessions

        http://www.itk.org/HTML/Tutorials.htm

in particular to

http://www.itk.org/CourseWare/Training/GettingStarted-V.pdf




Regards,


    Luis


---------------------------
Bernhard Mayrhofer wrote:

> Hello,
> I have an int- Array with grey values. In a first step i want to pass it 
> to a itk image which i want to use for registering purposes. I tried to 
> use iterators for fast access. To check the result, i tried ti write it 
> out, but this dies not work. The message I get is:
>  
> itk::ExceptionObject (0012F454)
> Location: "Unknown"
> File: f:\itk\insight\code\io\itkimagefilewriter.txx
> Line: 143
> Description: itk::ERROR: ImageFileWriter(02260618): No ImageIO set, or 
> none could be created.
>  
> The code I used:
>  
>  const unsigned int Dimension = 2;
>  typedef int PixelType;
>  typedef itk::Image< PixelType, Dimension >  ImageType;  
>  typedef itk::ImageRegionConstIterator< ImageType > ConstIteratorType;
>  typedef itk::ImageRegionIterator< ImageType>       IteratorType;
>  typedef itk::ImageFileWriter< ImageType > WriterType;
>  
> 
>  ImageType::Pointer image = ImageType::New();
>  ImageType::IndexType start;
>  ImageType::SizeType  size;
>  size[0]  = W;
>  size[1]  = W;
>  start[0] =   0;
>  start[1] =   0;
>  ImageType::RegionType region;
>  region.SetSize( size );
>  region.SetIndex( start );
>  image->SetRegions( region );
>  image->Allocate();
>  ImageType::PixelType  initialValue = 0;
>  image->FillBuffer( initialValue );
>  
>  IteratorType outputIt( image, image->GetRequestedRegion() );
>  
>  i=0;
>  for (outputIt.GoToBegin(); !outputIt.IsAtEnd();++outputIt)
>  {
>   outputIt.Set(Image[i/W][i%W]); // dynamic int array Image
>   i++;
>  }
>  
>  WriterType::Pointer writer = WriterType::New();
>  
>  writer->SetInput( image );
>  writer->SetFileName("test.raw");
>  try
>     {
>   writer->Update();
>     }
>  
>  catch ( itk::ExceptionObject &err)
>     {
>   std::cerr << "ExceptionObject caught !" << std::endl;
>   std::cerr << err << std::endl;
>     }
>  
> It would be fine, if i can register rgb values. is there a possibility. 
> But this topic isn´t hot at time. First I´m interessted why i get an 
> exception.
>  
> Thanks for any help
> Bernhard
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users






More information about the Insight-users mailing list