[Insight-users] know an image pixel type at reading

HIRAKI Hideaki hhiraki@lab.nig.ac.jp
Wed May 19 13:14:53 EDT 2004


Hi Jerome,

At Wed, 19 May 2004 09:32:33 +0200, jerome schmid wrote:
> So my question is, is there a way to read from an image, wihtout loading it,
> the pixel type which is storen in an header in order to retrieve it ( like
> an RTTI typeinfo for instance )? I don't want to write wrappers for all the
> kind of images that exist, itk does it so well!
> 

My code snippet:

  itk::ImageIOBase::Pointer imageIO =
    itk::ImageIOFactory::CreateImageIO(file, itk::ImageIOFactory::ReadMode);
  imageIO->SetFileName(file);
  imageIO->ReadImageInformation();
  switch( imageIO->GetComponentType() ){
  case itk::ImageIOBase::UCHAR:
    doProcess< itk::Image< unsigned char, Dimension> >(file);
    break;
  case itk::ImageIOBase::USHORT:
    doProcess< itk::Image< unsigned short, Dimension> >(file);
    break;
  default:
    std::cerr << "pixel must be unsignd char/short: " << file << std::endl;
    exit(1);
  }

I hope this helps.

Hideaki Hiraki



More information about the Insight-users mailing list