[Insight-developers] image data type
Bill Lorensen
bill.lorensen at gmail.com
Tue Mar 13 13:16:47 EST 2007
Leila,
Here's what I do to get the native pixel and component types from a file.
Then I instantiate the proper reader and filters.
Also, as Kent said, you can always instantiate a reader with the most
inclusive type your data can have (e.g. float) and the reader will convert
your input type to the requested type.
Bill
// Description:
// Get the PixelType and ComponentType from fileName
void GetImageType (std::string fileName,
ImageIOBase::IOPixelType &pixelType,
ImageIOBase::IOComponentType &componentType)
{
typedef itk::Image<unsigned char, 3> ImageType;
itk::ImageFileReader<ImageType>::Pointer imageReader =
itk::ImageFileReader<ImageType>::New();
imageReader->SetFileName(fileName.c_str());
imageReader->UpdateOutputInformation();
pixelType = imageReader->GetImageIO()->GetPixelType();
componentType = imageReader->GetImageIO()->GetComponentType();
}
On 3/13/07, kent williams <norman-k-williams at uiowa.edu> wrote:
>
> When you read a file with ImageIO, it will handle pixel type conversion
> from
> the pixel type of the image file and the image type you specify when you
> instantiate the ImageFileReader.
>
> If you look at the ImageFileReader header, there is a default
> ConvertPixelTraits template parameter, which does the 'normal' thing to
> convert between common pixel types. You can specify your own
> ConvertPixelTraits class if you want to do something different than the
> default.
>
> When you write a file with itkImageFileWriter, the ImageFileWriter will
> attempt to write an image with the pixel type for the ImageType you give
> at
> instantiation. If you attempt to write out an image with a pixel type
> unsupported by the selected file format, the ImageIO for that file format
> will either throw an exception or return an error.
>
>
> On 3/13/07 10:33 AM, "Leila Baghdadi" <baghdadi at sickkids.ca> wrote:
>
> > Hi guys,
> >
> > I am just wondering about the following,
> >
> > so far whenever I read an image, I made sure I knew the data type of the
> > image in advance and used itkImage with the correct data type.
> >
> > so the question is if I did not want to bother with checking image data
> > type in advance and just want to read the image, is there a way to make
> > the code deal with data type. or should the image factory be changed.
> >
> > any thoughts
> >
> > Leila
> >
> > _______________________________________________
> > Insight-developers mailing list
> > Insight-developers at itk.org
> > http://www.itk.org/mailman/listinfo/insight-developers
>
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.itk.org/mailman/private/insight-developers/attachments/20070313/fcb85067/attachment.htm
More information about the Insight-developers
mailing list