[Insight-users] Trouble reading and writing vector images

Gomez, Alberto alberto.gomez at kcl.ac.uk
Mon Feb 22 12:16:31 EST 2010


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>



More information about the Insight-users mailing list