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

Ivan Macia imacia@vicomtech.es
Wed May 19 13:11:13 EDT 2004


Hi Jerome,

>From what I understand, when you instantiate an ImageFileReader object you
specify the pixel type you want to work with in your program independently
from the pixel type you actually read from the file. The ImageIO object
associated with the ImageFileReader class determines at runtime which pixel
type is stored in the file (this is done by a ImageIOBase derived class,
which is also instantiated an runtime unless you provide it explicitly).
After this, that type you read is converted to the type you have chosen to
instantiate the ImageFileReader template (this is done in the
DoConvertBuffer() method), which will be the pixel type you are going to
work with internally. This way you don't really have to care about which
type is really stored in the file. In any case the ImageIOBase class
provides a GetPixelType() method reimplemented in its derived classes that
provides this information.

In my application I read volumes in Meta Image format which can be stored in
any pixel type but I internally work with floating point types. This way, I
instantiate the template in the form ImageFileReader<Image<float,3>>. Be
careful with pixel conversions, for example if you instantiate your file
reader with unsigned char and in your file you have unsigned short values
stored. I don't know the default behaviour but definitely you are losing
precision.

I dont't know if I have answered your question with this but I hope it
clarifies the mechanism a bit.

Regards

Iván


> -----Mensaje original-----
> De: insight-users-admin@itk.org [mailto:insight-users-admin@itk.org]En
> nombre de jerome schmid
> Enviado el: miércoles, 19 de mayo de 2004 9:33
> Para: insight-users@itk.org
> Asunto: [Insight-users] know an image pixel type at reading
>
>
> Hi everybody,
>
> I have a question about image reading from file. Itk intensive use of
> template has a lot of advantages but present a little
> problem, and before I
> may say stupid things, I want to ask you if there is already
> a way to solve
> my problem.
>
> When reading an image from file we define a type of reader as
> a combination
> of image pixel type and dimension:
>
> typedef itk::Image< PixelType, dim > InImageType
>
> A lot of type of image, like tiff for instance, define in
> their header the
> pixel type, like for example unsigned short, unsigned char, etc.
>
> So in order to create an appropriate reader, you must know
> before, that is
> to say when you write your code as everything is templated
> and not dynamic,
> the pixel type...! How it is possible if you know it
> dynamically when you
> open the file?
>
> I know the typelist mechanism which allows you to write a
> kind of switch on
> image type which will instanciate the good reader, even if
> the compilation
> can be long due to all the pixel type possible you have chosen to
> support...But this tricky system works at condition that you can know
> dynamically the pixel type you will use after.
>
> 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!
>
> Thanks!
>
> Jerome
>
>
>
>




More information about the Insight-users mailing list