[Insight-users] Registering ImageIO factories

Luis Ibanez luis . ibanez at kitware . com
Mon, 03 Jun 2002 09:50:38 -0400


Hi cspl,

You do have to register an IO factory in
order to be able to read an image file.

ImageFileReader<> is only a front end that
provides a uniform interface to the data
pipeline. The actual file reading is done
by the ImageIO objects.

This structure allows you to modularly add
as many image format readers as you wish,
without having to change your code.

Please add the line:

itk::RawImageIOFactory::RegisterOneFactory();

If you don't register any ImageIO factory,
the ImageFileReader will just report that
it cannot read the .raw file.

The 'report' is sent in the form of an Exception !


You may also want to put the reading code
in a try/catch block, like:

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


ITK exceptions print a description of the
error and the location where it was originated.

This will help you to identify the reasons
for the failure.



   Luis


======================================
cspl wrote:
> Dear Mr.Luis,
> 
> I have written code as follows.I am getting exception when run time.Actually
> I am not registring the RawImageIOfactory.How to make it register in code.I
> have added the line to my code.It is giving errors.How to register and get
> the  o/p .If you don't mind please follow through my code and tell me in
> which way I have to follow.
> 
> int main(int argc, char* argv[])
> {
> 
> 
>   UnsignedImageType::RegionType requestedRegion;
>   UnsignedImageType::SizeType  size;
>   UnsignedImageType::IndexType index;
> 
> 
>   //Set the size of the image region
>   //If you want to try a 2D image, you need to change the dimension.
>   size[0] = 256;
>   size[1] = 128;
>   size[2] = 10;
> 
>   index[0] = 0;
>   index[1] = 0;
>   index[2] = 0;
> 
>   requestedRegion.SetSize(size);
>   requestedRegion.SetIndex(index);
>  typedef itk::Image<char,3>  ImageType;
>   typedef itk::ImageFileReader< ImageType >  ReaderType;
>   ReaderType::Pointer reader = ReaderType::New();
>   reader->SetFileName("c:\\dicomfiles\\download\\xyz\\1.raw");
> //itk::RawImageIOFactory::RegisterOneFactory();
>   reader->Update();
>   cout<<"Laplacian filter test"<<endl;
>   itk::LaplacianImageFilter<ImageType, ImageType>::Pointer
>   lapFilter = itk::LaplacianImageFilter<ImageType, ImageType>::New();
>   lapFilter->SetInput(reader->GetOutput());
>   cout<<lapFilter->GetOutput();
> 
>   return EXIT_SUCCESS;
> }
> Now If I am calling reader->Update(),it is showing message box abnormal
> termination.If commented on both update and RawImageIOfactory,I am getting
> properties and  exception like follows.
> The instruction at "0x10217a50"referenced memory at "0x000000000".The memory
> could not be "read".
> And how to set image size and spacing .There is no functions to call setsize
> and setdataspacing.
> Please give me suggestion.
> 
> Thanking you,
> 
> 
> Regards,
> Ramakrishna
> 
> 
> 
>