[Insight-users] When to set image spacing?

Luis Ibanez luis.ibanez at kitware.com
Sat Aug 8 19:18:55 EDT 2009


Hi David,

The settings of Origin, Spacing and Direction are independent
of the memory allocation process. You could do it after or before.


There shouldn't be any difference between an image for which
you assigned the spacing before Allocate() and the one for which
you assigned the spacing after Allocate().


Something else should be going on here...


Have you verified the values of spacing by opening the .vtk
files with a text editor ?

BTW: I couldn't get to the two links that you posted.


     Regards,


             Luis


-----------------------------------------------------------------------
On Thu, Jul 30, 2009 at 1:22 PM, David Doria
<daviddoria+itk at gmail.com<daviddoria%2Bitk at gmail.com>
> wrote:

> The following code works correctly, and produces
> rpi.edu/~doriad/test_ok.vtk <http://rpi.edu/%7Edoriad/test_ok.vtk> (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)
>
> typedef itk::Image< float, 3 > ImageType;
> ImageType::Pointer image = ImageType::New();
>
>     ImageType::IndexType start;
>     start[0] = 0;  // first index on X
>     start[1] = 0;  // first index on Y
>     start[2] = 0;  // first index on Z
>
>     ImageType::SizeType  size;
>     size[0] = 20;  // size along X
>     size[1] = 20;  // size along Y
>     size[2] = 20;  // size along Z
>
>     ImageType::RegionType region;
>       region.SetSize( size );
>     region.SetIndex( start );
>     image->SetRegions( region );
>
>     image->Allocate();
>
>     ImageType::SpacingType spacing;
>     spacing[0] = .5;
>     spacing[1] = .5;
>     spacing[2] = .5;
>     image->SetSpacing(spacing);
>
>
> However, if the spacing setting is moved to before the allocate(), the z=0
> voxels are not uniformly zero (again, via visualization in paraview)
> http://www.rpi.edu/~doriad/test_bad.vtk<http://www.rpi.edu/%7Edoriad/test_bad.vtk>
>
>
> typedef itk::Image< float, 3 > ImageType;
> ImageType::Pointer image = ImageType::New();
>
>     ImageType::IndexType start;
>     start[0] = 0;  // first index on X
>     start[1] = 0;  // first index on Y
>     start[2] = 0;  // first index on Z
>
>     ImageType::SizeType  size;
>     size[0] = 20;  // size along X
>     size[1] = 20;  // size along Y
>     size[2] = 20;  // size along Z
>
>     ImageType::RegionType region;
>       region.SetSize( size );
>     region.SetIndex( start );
>     image->SetRegions( region );
>
>   //this block is now moved BEFORE allocate
>     ImageType::SpacingType spacing;
>     spacing[0] = .5;
>     spacing[1] = .5;
>     spacing[2] = .5;
>     image->SetSpacing(spacing);
>
>     image->Allocate();
>
>
> 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.
>
> Thanks,
>
> David
>
> _____________________________________
> 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/20090808/2b5c0eda/attachment.htm>


More information about the Insight-users mailing list