<br>Hi David,<br><br>The settings of Origin, Spacing and Direction are independent<br>of the memory allocation process. You could do it after or before.<br><br><br>There shouldn't be any difference between an image for which<br>
you assigned the spacing before Allocate() and the one for which<br>you assigned the spacing after Allocate().<br><br><br>Something else should be going on here...<br><br><br>Have you verified the values of spacing by opening the .vtk<br>
files with a text editor ?<br><br>BTW: I couldn't get to the two links that you posted.<br><br><br> Regards,<br><br><br> Luis<br><br><br>-----------------------------------------------------------------------<br>
<div class="gmail_quote">On Thu, Jul 30, 2009 at 1:22 PM, David Doria <span dir="ltr"><<a href="mailto:daviddoria%2Bitk@gmail.com">daviddoria+itk@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;">
The following code works correctly, and produces <a href="http://rpi.edu/%7Edoriad/test_ok.vtk" target="_blank">rpi.edu/~doriad/test_ok.vtk</a> (there was a few more lines to set 3 voxels to non-zero values). Visualized with 'representation=slice' in paraview, the first slice is uniform in color (should be all 0 except one corner pixel)<br>
<br>typedef itk::Image< float, 3 > ImageType;<br> ImageType::Pointer image = ImageType::New();<br> <br> ImageType::IndexType start;<br> start[0] = 0; // first index on X<br> start[1] = 0; // first index on Y<br>
start[2] = 0; // first index on Z<br> <br> ImageType::SizeType size;<br> size[0] = 20; // size along X<br> size[1] = 20; // size along Y<br> size[2] = 20; // size along Z<br> <br> ImageType::RegionType region;<br>
region.SetSize( size );<br> region.SetIndex( start );<br> image->SetRegions( region );<br> <br> image->Allocate();<br> <br> ImageType::SpacingType spacing;<br> spacing[0] = .5;<br> spacing[1] = .5;<br>
spacing[2] = .5;<br> image->SetSpacing(spacing);<br><br><br>However, if the spacing setting is moved to before the allocate(), the z=0 voxels are not uniformly zero (again, via visualization in paraview) <a href="http://www.rpi.edu/%7Edoriad/test_bad.vtk" target="_blank">http://www.rpi.edu/~doriad/test_bad.vtk</a><br>
<br><br>
typedef itk::Image< float, 3 > ImageType;<br>
ImageType::Pointer image = ImageType::New();<br>
<br>
ImageType::IndexType start;<br>
start[0] = 0; // first index on X<br>
start[1] = 0; // first index on Y<br>
start[2] = 0; // first index on Z<br>
<br>
ImageType::SizeType size;<br>
size[0] = 20; // size along X<br>
size[1] = 20; // size along Y<br>
size[2] = 20; // size along Z<br>
<br>
ImageType::RegionType region;<br>
region.SetSize( size );<br>
region.SetIndex( start );<br>
image->SetRegions( region );<br>
<br>
//this block is now moved BEFORE allocate<br>
ImageType::SpacingType spacing;<br>
spacing[0] = .5;<br>
spacing[1] = .5;<br>
spacing[2] = .5;<br>
image->SetSpacing(spacing);<br>
<br>
image->Allocate();<br><br><br>Is it supposed to work like that? (i.e. you have to allocate() the image before you set it's properties like spacing/origin?). Also, is there a way to initialize the image so all pixels have a constant non-zero value? I can post the entire code in a file if necessary, but the problem seemed localized to this bit.<br>
<br clear="all">Thanks,<br><font color="#888888"><br>David<br>
</font><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>
<br></blockquote></div><br>