[Insight-users] Trouble reading and writing vector images

Luis Ibanez luis.ibanez at kitware.com
Mon Feb 22 18:32:14 EST 2010


Hi Alberto,


1) What file format are you using for saving the vector image ?


2) You email asks about itk::VectorImage, but the typedef
    that you show actually uses:

                   pixeltype = itk::Vector

     are you actually using the itk::VectorImage in your code ?

3) The memory organization of

               itk::VectorImage< float, N >                         (A)

     will be different from the memory organization of

               itk::Image<  itk::Vector< float, N > ,  N >     (B)

In the case of (A) you will have first all the values of the
first vector component of all the pixels, followed by the
values of all the second components of all the pixels,
followed by the third component of all the pixels... etc.

In the case of (B), you have first the N components of
the first pixel, followed by the N components of the second
pixel, followed by the N components of the third pixel...etc.


Please clarify what code you are using, and what file format.


        Thanks


                Luis



-----------------------------------
On Mon, Feb 22, 2010 at 12:16 PM, Gomez, Alberto
<alberto.gomez at kcl.ac.uk> wrote:
> Hi all,
>
> I am having some unexpected results when reading and writing vector images.
> The example would be the following. I have a vector image called
> "fullVectors_resampled". I give a value to every pixel and then write it to
> a file. Then I load it and the values have changed!!!
>
>
>       VectorImageType::IndexType index;
>       VectorImageType::PixelType vector;
>       vector[0] = 1;
>       vector[1] = 2;
>       vector[2]= 3;
>
>       for (int i = 0;
> i<fullVectors_resampled->GetLargestPossibleRegion().GetSize()[0]; i++ ){
>           index[0] = i;
>           for (int j = 0;
> j<fullVectors_resampled->GetLargestPossibleRegion().GetSize()[1]; j++ ){
>               index[1]=j;
>               for (int k = 0;
> k<fullVectors_resampled->GetLargestPossibleRegion().GetSize()[2]; k++ ){
>                   index[2]=k;
>
>                   fullVectors_resampled->SetPixel(index, vector);
>
>               }
>
>           }
>      }
>
>
>       WriterVectorType::Pointer writer = WriterVectorType::New();
>       writer->SetFileName(filename);
>       writer->SetInput(fullVectors_resampled);
>       writer->Write();
>
>
>       ReaderVectorType::Pointer reader2 = ReaderVectorType::New();
>       reader2->SetFileName(filename);
>       reader2->Update();
>       VectorImageType::Pointer image1g2 = reader2->GetOutput();
>
>
>       for (int i = 0;
> i<fullVectors_resampled->GetLargestPossibleRegion().GetSize()[0]; i++ ){
>                   index[0] = i;
>                   for (int j = 0;
> j<fullVectors_resampled->GetLargestPossibleRegion().GetSize()[1]; j++ ){
>                       index[1]=j;
>                       for (int k = 0;
> k<fullVectors_resampled->GetLargestPossibleRegion().GetSize()[2]; k++ ){
>                           index[2]=k;
>
>                           std::cout <<
> fullVectors_resampled->GetPixel(index) << "    "
>                                << image1g2->GetPixel(index) << std::endl;
>
>                           fullVectors_resampled->SetPixel(index, vector);
>
>                       }
>
>                   }
>           }
>
> As I am reading the image that I just wrote, I would expect that the vectors
> are the same... but the output I get is:
>
> [1, 2, 3]    [1, 1, 1]
> [1, 2, 3]    [2, 2, 2]
> [1, 2, 3]    [3, 3, 3]
> [1, 2, 3]    [1, 1, 1]
> [1, 2, 3]    [2, 2, 2]
> [1, 2, 3]    [3, 3, 3]
> ...
> ...
> ...
> ...
> [1, 2, 3]    [1, 1, 1]
> [1, 2, 3]    [2, 2, 2]
> [1, 2, 3]    [3, 3, 3]
>
> I think this has to do with how memory is organised in these images. I am
> using the following definition for my VectorImageType:
>
> typedef itk::Vector<float, 3> VectorPixelType;
> typedef itk::Image<VectorPixelType, 3> VectorImageType;
>
> And from the itkVectorImage documentation,
>
> "This class differs from Image
> <http://www.itk.org/Doxygen316/html/classitk_1_1Image.html> in that it is
> intended to represent multiple images. Each pixel represents /k/
> measurements, each of datatype /TPixel/. The memory organization of the
> resulting image is as follows: ... Pi0 Pi1 Pi2 Pi3 P(i+1)0 P(i+1)1 P(i+1)2
> P(i+1)3 P(i+2)0 ... where Pi0 represents the 0th measurement of the pixel at
> index i."
>
> Does this mean that my VectorImageType is organised Pi0 P(i+1)0 ... P(i)1
> P(i+1)1...P(i)2 P(i+1)2... etc? Anyone has already experienced this? Is this
> supposed to work this way?
>
>
>
>
> --
>
> Alberto Gómez
>
> /Division of Imaging Sciences
> The Rayne Institute
> 4th Floor, Lambeth Wing
> St Thomas' Hospital
> London SE1 7EH /
>
> phone: +44 (0) 20 718 88364
> email: alberto.gomez at kcl.ac.uk <mailto:alberto.gomez at kcl.ac.uk>
>
> _____________________________________
> 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://www.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-users
>


More information about the Insight-users mailing list