[Insight-developers] Wrong behaviour of ImageFileReader when reading an itk::VectorImage<itk::FixedArray<double, 6>, 3> ?

Karthik Krishnan karthik.krishnan at kitware.com
Tue Jan 18 08:31:47 EST 2011


On Fri, Jan 14, 2011 at 6:26 AM, Benoit Scherrer
<benoitscherrer at gmail.com>wrote:

> Hi,
>
> I wanted to use the type:
> typedef itk::VectorImage<itk::FixedArray<double, 6>, 3> TensorVectorImage;
> to make a vector image of tensors.
>
> Everything compiles well. But when i use the
> itk::ImageFileReader<TensorVectorImage>
> it seems that things goes wrong. When trying to iterate on the image :
>
> itk::ImageRegionConstIterator<TensorVectorImage>
>  it(image, image->GetLargestPossibleRegion());
>  while(!it.IsAtEnd())
> {
> itk::VariableLengthVector<itk::FixedArray<double, 6> > tensors = it.Get();
>                (...)
> ++it;
> }
>
> it compiles but during the execution goes out of the data bounds.
>
> By looking into ImageFileReader<TOutputImage,
> ConvertPixelTraits>::GenerateOutputInformation
> I found the lines:
>
>   if( strcmp( output->GetNameOfClass(), "VectorImage" ) == 0 )
>     {
>     typedef typename TOutputImage::AccessorFunctorType AccessorFunctorType;
>     AccessorFunctorType::SetVectorLength( output,
> m_ImageIO->GetNumberOfComponents() );
>     }
>
> So here m_ImageIO->GetNumberOfComponents() will returns 6 for a simple
> tensor file (Dimension
> of the VectorImage = 1), instead of 1 (after the offsets computed
> in ImageRegionConstIterator are wrong).
>
> So should ImageFileReader divides m_ImageIO->GetNumberOfComponents() by the
> number of components
> of TOutputImage::PixelType ? (i manually set it to 1 in the debugger, it's
> working. However i didn't tried
> with an image with 12 components, ie two tensors)
>

I don't know of a way to get the number of components in
TOutputImage::PixelType. It would require us to define a NumberOfComponents
in the traits of all pixels in itkNumericTraits.

The IO class has no way of knowing the specific pixel type you've
instantiated. One has to rely on the IO, for instance if the pixel type is
an Array, (in which case, the image cannot tell you the number of components
in the array. The IO tells you by parsing the file). You have a peculiar
situation where you want to get the number of components from the pixel and
not from the IO.

I can think of a crude way of doing it for now, perhaps try :

    typedef TOutputImage::PixelType OutPixelType;
    int nComponentsInPixelType =
sizeof(OutPixelType::RealType)/sizeof(OutPixelType::ScalarRealType);
    AccessorFunctorType::SetVectorLength( output, nComponentsInPixelType  );

But it would break if the pixel type is an Array etc.



> Or is it a bad idea to use  itk::VectorImage<itk::FixedArray<double, 6>, 3>
>  ?
>
> Thanks a lot
> Benoit
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> 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/20110118/de20fb7d/attachment.htm>


More information about the Insight-developers mailing list