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

Bernhard Mayrhofer berninho1 at hotmail.com
Sun Sep 5 17:48:31 EDT 2004


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20040905/6efe3035/attachment.html


More information about the Insight-users mailing list