vtkImageReslice: can not get slice, extent[6] are all 0

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

vtkImageReslice: can not get slice, extent[6] are all 0

VTK - Dev mailing list

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
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Search the list archives at: http://markmail.org/search/?q=vtk-developers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtk-developers

Reply | Threaded
Open this post in threaded view
|

Re: vtkImageReslice: can not get slice, extent[6] are all 0

VTK - Dev mailing list
Can anyone  find the problems?



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Dev-f1251487.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Search the list archives at: http://markmail.org/search/?q=vtk-developers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtk-developers

Reply | Threaded
Open this post in threaded view
|

Re: vtkImageReslice: can not get slice, extent[6] are all 0

wyldckat
Quoting from an email from a couple of weeks ago:
-------- Forwarded Message --------
Subject: [vtk-developers] Fwd: VTK Discourse forum is now available
Date: Thu, 28 Feb 2019 16:13:04 -0500
From: Cory Quammen via vtk-developers [hidden email]
Reply-To: Cory Quammen [hidden email]
To: vtkusers [hidden email], VTK Developers [hidden email]


Hi folks,

Just a reminder that the mailing lists [hidden email] and [hidden email] will be retired at some point this year. Please post new questions and topics on https://discourse.vtk.org

Details are available in the forwarded message below.

Thank you,
Cory

On 09/03/2019 17:42, richard anderson via vtk-developers wrote:
Can anyone  find the problems? 



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Dev-f1251487.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Search the list archives at: http://markmail.org/search/?q=vtk-developers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtk-developers




--
www.bluecape.com.pt
an FS Dynamics company

FSD blueCAPE Lda
Rua Fonte dos Corvos 29
Casais da Serra
2665-305 Milharado
PORTUGAL

T: (+351) 926 008 657


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Search the list archives at: http://markmail.org/search/?q=vtk-developers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtk-developers