[vtkusers] vtkImageReslice and vtkImageViewer

Talita Perciano talitaperciano at gmail.com
Tue Sep 23 22:16:53 EDT 2008


Hello,

I'm trying to read DICOM image slices and to view them with a
vtkImageViewer. The thing is that I want to change the axis before I view
the slices, that is, if the slices are in axial direction I want to change
it to coronal direction. I'm doing that using the a vtkImageReslice. The
thing is that when I pass the DICOM reader directly to the vtkImageViewer
things work fine. However, when I use first the vtkImageReslice and than
pass it to the vtkImageViewer I can't view the slices anymore. It's strange
because when I call GetWholeZMax it returns 0. Does anybody could help me?
The code is attached.

Thank you,

Talita

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

        std::string strFolderPath = "/home/talita/Desktop/COMUNIX/Neck
1HEAD_NECK_PETCT/CT HEAD-NK 5.0 B30s";

        vtkDICOMImageReader *reader = vtkDICOMImageReader::New();
        reader->SetDirectoryName (strFolderPath.c_str());
        reader->Update();

    reader->SetDataScalarTypeToUnsignedShort();
      reader->UpdateWholeExtent();

      // Calculate the center of the volume
      reader->GetOutput()->UpdateInformation();
      int extent[6];
      double spacing[3];
      double origin[3];
      reader->GetOutput()->GetWholeExtent(extent);
      reader->GetOutput()->GetSpacing(spacing);
      reader->GetOutput()->GetOrigin(origin);

      double center[3];
      center[0] = origin[0] + spacing[0] * 0.5 * (extent[0] + extent[1]);
      center[1] = origin[1] + spacing[1] * 0.5 * (extent[2] + extent[3]);
      center[2] = origin[2] + spacing[2] * 0.5 * (extent[4] + extent[5]);

      // Matrices for axial, coronal, sagittal, oblique view orientations
      static double axialElements[16] = {
               1, 0, 0, 0,
               0, 1, 0, 0,
               0, 0, 1, 0,
               0, 0, 0, 1 };

      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 };

      //static double obliqueElements[16] = {
      //         1, 0, 0, 0,
      //         0, 0.866025, -0.5, 0,
      //         0, 0.5, 0.866025, 0,
      //         0, 0, 0, 1 };

      // Set the slice orientation
      vtkMatrix4x4 *resliceAxes = vtkMatrix4x4::New();
      resliceAxes->DeepCopy(coronalElements);
      // Set the point through which to slice
      resliceAxes->SetElement(0, 3, center[0]);
      resliceAxes->SetElement(1, 3, center[1]);
      resliceAxes->SetElement(2, 3, center[2]);

      // Extract a slice in the desired orientation
      vtkImageReslice *reslice = vtkImageReslice::New();
      reslice->SetInputConnection(reader->GetOutputPort());
      reslice->SetOutputDimensionality(2);
      reslice->SetResliceAxes(resliceAxes);
      //reslice->SetInterpolationModeToNearestNeighbor();

      // Create a greyscale lookup table
      vtkLookupTable *table = vtkLookupTable::New();
      table->SetRange(0, 2000); // image intensity range
      table->SetValueRange(0.0, 1.0); // from black to white
      table->SetSaturationRange(0.0, 0.0); // no color saturation
      table->SetRampToLinear();
      table->Build();

      // Map the image through the lookup table
      vtkImageMapToColors *color = vtkImageMapToColors::New();
      color->SetLookupTable(table);
      color->SetInputConnection(reslice->GetOutputPort());

    vtkImageViewer *viewer = vtkImageViewer::New();

    viewer->SetInput(color->GetOutput());
    printf("\n%d\n",viewer->GetWholeZMax());
    viewer->SetZSlice(35);
    viewer->SetColorWindow(2000);
    viewer->SetColorLevel(1000);
    viewer->Render();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080923/911e7200/attachment.htm>


More information about the vtkusers mailing list