[Insight-users] When to set image spacing?
David Doria
daviddoria+itk at gmail.com
Thu Jul 30 13:22:35 EDT 2009
The following code works correctly, and produces
rpi.edu/~doriad/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
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090730/5bb9c29b/attachment.htm>
More information about the Insight-users
mailing list