<br>Hi Motes,<br><br>The organization of components in the Index doesn't have to reflect<br>the same as the organization of pixels in the image memory.<br><br>ITK images currently allocate memory in a single block.<br>
<br>In the case of a 3D image, of size 150 x 170 x 190 you will<br>have the 150 pixels of the first image row, that goes along the<br>X axis, to be organized contiguously in memory. This row<br>will be followed by the X row, that follows it in the Y direction.<br>
<br>If you were moving the values of an Index in order to visit<br>the memory contiguously (which is what most Iterators do)<br><br>you will have to start with<br><br>index[0] = 0;<br>index[1] = 0;<br>index[2] = 0;<br><br>
to point to the first pixel.<br><br>Then you will visit the first 150 pixels in memory by <br>varying the index[0] from 0 to 149. Then, you will<br>increment index[1] to 1, and again visit the next 150<br>pixels in memory by varying index[0] from 0 to 149.<br>
and so on....<br><br>The reason why the itkImage.h documentation lists<br>many []s is that itkImages are N-Dimensional, and<br>we only have commonly used names for the first <br>three dimensions.<br><br>So we tend to say [slice][row][column].<br>
<br><br>Note that the ITK image doesn't have any operator[]<br>so, there is no option of calling image[0] at all.<br><br>Access to pixels should be done through<br><br> image->GetPixel( index );<br> image->SetPixel( index, value );<br>
<br>and preferably through<br><br> ImageIterators<br> (See the image iterators chapter in the <br> ITK Software Guide<br> <a href="http://www.itk.org/ItkSoftwareGuide.pdf">http://www.itk.org/ItkSoftwareGuide.pdf</a>)<br>
<br><br>--<br><br>The code that you are looking at in the <br>BSplineDeformableTransform is an entirely different<br>story.<br><br>What goes on there is that images are used for storing<br>each one of the components of the displacement vectors<br>
associated with the BSpline grid nodes.<br><br>So, for 2D we have two images of coefficients.<br>The image m_CoefficientsImage[0] contains all the<br>X components of the displacement vectors, while the<br>image m_CoefficientsImage[1] contains all the Y <br>
components.<br><br>If you wanted to get access to one of the displacement<br>vectors you will build it as:<br><br> Vector[0] = m_CoefficientImage[0]->GetPixel( index );<br> Vector[1] = m_CoefficientImage[1]->GetPixel( index );<br>
<br><br>This is a very specific use of the image structure,<br>and you may not want to use it as a representative<br>example of how the ITK image memory is accessed.<br><br><br> Regards,<br><br><br> Luis<br><br><br>
----------------------------------------------------------------<br><div class="gmail_quote">On Sun, Aug 23, 2009 at 5:14 PM, motes motes <span dir="ltr"><<a href="mailto:mort.motes@gmail.com">mort.motes@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">As I understand pixels in an image is located using a indexType:<br>
<br>
// 2D case:<br>
IndexType idx;<br>
idx[0] = 3;<br>
idx[1] = 4;<br>
<br>
ImageType::Pointer image = reader->GetOutPut(); // from some reader.<br>
image->GetPixel(idx);<br>
<br>
The above example get the value of the pixel at location (3,4) in the image.<br>
<br>
But in the itk::Image.h file it says:<br>
<br>
*<br>
* The data in an image is arranged in a 1D array as [][][][slice][row][col]<br>
* with the column index varying most rapidly. The Index type reverses<br>
* the order so that with Index[0] = col, Index[1] = row, Index[2] = slice,<br>
* ...<br>
<br>
I don't understand this notation:<br>
<br>
[][][][slice][row][col]<br>
<br>
does it mean that if I do:<br>
<br>
image[0];<br>
<br>
I get the first whole column of the image? And what does the prefix<br>
[][][]...stand for?<br>
<br>
<br>
<br>
<br>
<br>
<br>
//Example:<br>
In the BSplineDeformableTransform images m_WrappedImage and<br>
m_CoefficientImage are used like this:<br>
<br>
PixelType * dataPointer = const_cast<PixelType *>((<br>
m_InputParametersPointer->data_block() ));<br>
unsigned int numberOfPixels = m_GridRegion.GetNumberOfPixels();<br>
<br>
for ( unsigned int j = 0; j < SpaceDimension; j++ ) {<br>
m_WrappedImage[j]->GetPixelContainer()->SetImportPointer(<br>
dataPointer, numberOfPixels );<br>
dataPointer += numberOfPixels;<br>
m_CoefficientImage[j] = m_WrappedImage[j];<br>
}<br>
<br>
To my understanding this first sets the column of m_WrappedImage to<br>
the first half of the parameters and then copies that to the<br>
m_CoefficientImage. Next the last half of the parameters are copied to<br>
the row of m_WrappedImage and then copied to m_CoefficientImage. But I<br>
am pretty sure this is not what goes on, what does:<br>
<br>
m_CoefficientImage[0]<br>
m_CoefficientImage[1]<br>
<br>
actually mean for the 2D case?<br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at: <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</blockquote></div><br>