[vtk-developers] vtkImageReslice: can not get slice, extent[6] are all 0
richard anderson
richardander at yahoo.com
Thu Mar 7 15:39:53 EST 2019
Hello,
I have a series of images, each of which stores its pixel data (double) in
m_pImagePixel. I would like to get the slice along x, y and z directions at
center of pixel data block. Following are what I did.
1. create image pixel data of whole series : p3DImageData.
2. use vtkImageImporter to load p3DImageData;
3. use vtkImageReslice to get data from vtkImageImporter;
4. get slice along x,y,z.
Following is the code. I used three 4x4 matrix to change direction and get
images by using the same m_reslice. However,
(1) the extent[6] are 0, regardless which direction is used;
(2) when axialElements is used, I can get correct pixel data for display.
But using coronalElements and sagittalElements generate messy pixel data in
slice;
Please help point out what is wrong in my code.
Thank you!
//static double coronalElements[16] = {
// 1, 0, 0, 0,
// 0, 0, 1, 0,
// 0,-1, 0, 0,
// 0, 0, 0, 1 };
// static double sagittalElements[16] = {
// 0, 0,-1, 0,
// 1, 0, 0, 0,
// 0,-1, 0, 0,
// 0, 0, 0, 1 };
// Prepare image pixel;
double * p3DImageData = new double [ image_width * image_height *
image_depth ];
for(int idx=0; idx<image_depth; idx++)
{
ImagePtr pImage = vImagePtr[idx];
if(!pImage->m_pImagePixel)
pImage->LoadPixelData();
memcpy( p3DImageData + imageSize*idx, pImage->m_pImagePixel, imageSize *
sizeof(double) );
}
// Create image importer
vtkSmartPointer<vtkImageImport> imageImporter =
vtkSmartPointer<vtkImageImport>::New();
imageImporter->SetWholeExtent(0, image_width-1, 0, image_height-1, 0,
image_depth-1);
imageImporter->SetDataExtentToWholeExtent();
imageImporter->SetDataScalarTypeToDouble();
imageImporter->SetImportVoidPointer((void *) p3DImageData );
imageImporter->Update();
imageImporter->GetOutput()->GetExtent(m_extent);
imageImporter->GetOutput()->GetSpacing(m_spacing);
imageImporter->GetOutput()->GetOrigin(m_origin);
// Get reslice data;
vtkSmartPointer<vtkImageReslice> m_reslice =
vtkSmartPointer<vtkImageReslice>::New();
m_reslice->SetInputConnection(imageImporter->GetOutputPort());
center[0] = m_origin[0] + m_spacing[0] * 0.5 * (m_extent[0] + m_extent[1]);
center[1] = m_origin[1] + m_spacing[1] * 0.5 * (m_extent[2] + m_extent[3]);
center[2] = m_origin[2] + m_spacing[2] * 0.5 * (m_extent[4] + m_extent[5]);
static double axialElements[16] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
// Set the slice orientation and center
vtkSmartPointer<vtkMatrix4x4> resliceAxes =
vtkSmartPointer<vtkMatrix4x4>::New();
resliceAxes->DeepCopy(axialElements);
resliceAxes->SetElement(0, 3, center[0]);
resliceAxes->SetElement(1, 3, center[1]);
resliceAxes->SetElement(2, 3, center[2]);
m_reslice->SetOutputDimensionality(2);
m_reslice->SetResliceAxes(resliceAxes);
m_reslice->SetInterpolationModeToLinear();
m_reslice->Update();
int extent[6];
m_reslice->GetOutputExtent(extent);
void * p = m_reslice->GetOutput()->GetScalarPointer();
memcpy( pAxialSliceData, (double *)p, image_width * image_height*
sizeof(double) );
// when changed to coronal or sagital directions, differnet 4x4 matrix is
used and memcpy() will use image_width * image_depth * sizeof (double) and
image_height * image_depth * sizeof (double) respectively .
--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Dev-f1251487.html
More information about the vtk-developers
mailing list