[Insight-users] Indexing itk::Image
Luis Ibanez
luis.ibanez at kitware.com
Wed Sep 9 14:57:33 EDT 2009
Hi Motes,
The organization of components in the Index doesn't have to reflect
the same as the organization of pixels in the image memory.
ITK images currently allocate memory in a single block.
In the case of a 3D image, of size 150 x 170 x 190 you will
have the 150 pixels of the first image row, that goes along the
X axis, to be organized contiguously in memory. This row
will be followed by the X row, that follows it in the Y direction.
If you were moving the values of an Index in order to visit
the memory contiguously (which is what most Iterators do)
you will have to start with
index[0] = 0;
index[1] = 0;
index[2] = 0;
to point to the first pixel.
Then you will visit the first 150 pixels in memory by
varying the index[0] from 0 to 149. Then, you will
increment index[1] to 1, and again visit the next 150
pixels in memory by varying index[0] from 0 to 149.
and so on....
The reason why the itkImage.h documentation lists
many []s is that itkImages are N-Dimensional, and
we only have commonly used names for the first
three dimensions.
So we tend to say [slice][row][column].
Note that the ITK image doesn't have any operator[]
so, there is no option of calling image[0] at all.
Access to pixels should be done through
image->GetPixel( index );
image->SetPixel( index, value );
and preferably through
ImageIterators
(See the image iterators chapter in the
ITK Software Guide
http://www.itk.org/ItkSoftwareGuide.pdf)
--
The code that you are looking at in the
BSplineDeformableTransform is an entirely different
story.
What goes on there is that images are used for storing
each one of the components of the displacement vectors
associated with the BSpline grid nodes.
So, for 2D we have two images of coefficients.
The image m_CoefficientsImage[0] contains all the
X components of the displacement vectors, while the
image m_CoefficientsImage[1] contains all the Y
components.
If you wanted to get access to one of the displacement
vectors you will build it as:
Vector[0] = m_CoefficientImage[0]->GetPixel( index );
Vector[1] = m_CoefficientImage[1]->GetPixel( index );
This is a very specific use of the image structure,
and you may not want to use it as a representative
example of how the ITK image memory is accessed.
Regards,
Luis
----------------------------------------------------------------
On Sun, Aug 23, 2009 at 5:14 PM, motes motes <mort.motes at gmail.com> wrote:
> As I understand pixels in an image is located using a indexType:
>
> // 2D case:
> IndexType idx;
> idx[0] = 3;
> idx[1] = 4;
>
> ImageType::Pointer image = reader->GetOutPut(); // from some reader.
> image->GetPixel(idx);
>
> The above example get the value of the pixel at location (3,4) in the
> image.
>
> But in the itk::Image.h file it says:
>
> *
> * The data in an image is arranged in a 1D array as
> [][][][slice][row][col]
> * with the column index varying most rapidly. The Index type reverses
> * the order so that with Index[0] = col, Index[1] = row, Index[2] = slice,
> * ...
>
> I don't understand this notation:
>
> [][][][slice][row][col]
>
> does it mean that if I do:
>
> image[0];
>
> I get the first whole column of the image? And what does the prefix
> [][][]...stand for?
>
>
>
>
>
>
> //Example:
> In the BSplineDeformableTransform images m_WrappedImage and
> m_CoefficientImage are used like this:
>
> PixelType * dataPointer = const_cast<PixelType *>((
> m_InputParametersPointer->data_block() ));
> unsigned int numberOfPixels = m_GridRegion.GetNumberOfPixels();
>
> for ( unsigned int j = 0; j < SpaceDimension; j++ ) {
> m_WrappedImage[j]->GetPixelContainer()->SetImportPointer(
> dataPointer, numberOfPixels );
> dataPointer += numberOfPixels;
> m_CoefficientImage[j] = m_WrappedImage[j];
> }
>
> To my understanding this first sets the column of m_WrappedImage to
> the first half of the parameters and then copies that to the
> m_CoefficientImage. Next the last half of the parameters are copied to
> the row of m_WrappedImage and then copied to m_CoefficientImage. But I
> am pretty sure this is not what goes on, what does:
>
> m_CoefficientImage[0]
> m_CoefficientImage[1]
>
> actually mean for the 2D case?
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090909/de3e9fb5/attachment-0001.htm>
More information about the Insight-users
mailing list