[Insight-users] Managing conversion of pixel types during fil e read

Miller, James V (Research) millerjv at crd.ge.com
Thu, 15 Apr 2004 12:16:29 -0400


It looks to me like the OutputComponentType used in the offending
static_cast<> is pulled from the OutputConvertTraits template parameter
of the ConvertPixelBuffer class.  The template parameter of the
ConvertPixelBuffer is set using the appropriate template parameter
of the image file reader.  It looks like what you want to do is:

typedef char PixelType;
typedef short SafeComponentType;  // could be float/double as a default
typedef itk::Image<PixelType, 2> MyImageType;
typedef MyPixelTraits<PixelType, SafeComponentType> MyTraits;

typedef itk::ImageFileReader<MyImageType, MyTraits>  MyReaderType;

template <typename PixelType, typename DummyComponentType=float>
class MyPixelTraits
{
  public:
    typedef typename DummyComponentType ComponentType;

  // Rest of MyPixelTraits craft to be careful with "ComponentType"
}


The trick here is to redefine the ComponentType of the PixelTraits to 
be something that will nullify the static_cast<> in ConvertPixelBuffer<>.
Then you need to be careful how ComponentType is used in the remainder
of your PixelTraits.





-----Original Message-----
From: Zachary Pincus [mailto:zpincus at stanford.edu]
Sent: Wednesday, April 14, 2004 7:54 PM
To: insight-users at itk.org
Subject: Re: [Insight-users] Managing conversion of pixel types during
file read


Hmm, after looking at DefaultConvertPixelTraits and ConvertPixelBuffer, 
I am not convinced that it is possible to create a input-type savvy 
ConvertPixelTraits.

While the documentation for DefaultConvertPixelTraits states:

> This implementaion, does a simple assignment operator, so if you are 
> going from from a higher bit representation to a lower bit one (int to 
> char), you may want to specialize and add some sort of transfer 
> function.

there does not seem to be any way to do this. For example, in the 
ConvertGrayToGray method of ConvertPixelBuffer, this gets called:

OutputConvertTraits
       ::SetNthComponent(0, *outputData++,
                         static_cast<OutputComponentType>
                         (*inputData));

Note the static_cast. So if you wanted to write a ConvertPixelTraits 
class that was savvy about, say, converting ints to chars (as per the 
documentation), you're out of luck because this conversion was already 
done in the static_cast in ConvertPixelBuffer. (I think.)

So it seems that you would really have to write a new version of 
ConvertPixelBuffer that was smart about transforming pixel types 
between each other. OK, this is a bit more of a pain than just writing 
a new ConvertPixelTraits, but whatever. However, even this is not 
possible, because it only seems possible to provide an ImageFileReader 
with a new version of the ConvertPixelTraits, not of the 
ConvertPixelBuffer class.

This seems to be due to the fact that this matter *should* be 
accomplishable through ConvertPixelTraits, but at least to my eye, it 
is not.

Am I missing something fundamental here? Or is it not currently 
possible to add a specialized pixel transfer function to an 
ImageFileReader?

Thanks,

Zach


On Apr 14, 2004, at 4:03 PM, Zachary Pincus wrote:

> Hello,
>
> My plan is to convert images I read in (initially in heterogeneous 
> pixel types) to floating-point pixels. I intend to rescale each image 
> such that the dynamic range of the image type (e.g. 8 bits, 16 bits) 
> is compressed to the floating-point range [0, 1].
>
> That is, I don't mean to "normalize" each image I read in so that 
> [image.min_value, image.max_value] goes to [0, 1], but to convert 
> [ImageType.min_possible_value, ImageType.max_possible_value] to [0, 
> 1]. (If you follow my abused notation!)
>
> Is there any simple way to do this in ITK now? I could write a new 
> version of DefaultConvertPixelTraits for use with the FileReaders, but 
> (a) I don't quite know what all needs to go into this, and (b) if 
> there's an easy way already, I should use that.
>
> Thanks,
> Zach Pincus
>
>
> Department of Biochemistry and Program in Biomedical Informatics
> Stanford University School of Medicine
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>

_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users