[vtkusers] Extracting Slices using vtkImageReslice - Calculating extract spacing factor

David Gobbi dgobbi at atamai.com
Sat Apr 21 12:10:06 EDT 2007


Hi Wagner,

I think that I know what the error in your code is.

Since you are setting the OutputSpacing() to minSpacing.  This means
the spacing of the output will always be minSpacing regardless of
whether you are looking at the x spacing, y spacing or z spacing.

Maybe what you should do instead is get the input spacing:

  m_ImageData->UpdateInformation();
  m_ImageData->GetSpacing()[i];

This will return the original spacing as stored in the DICOM file,
which will allow you to properly go through the data set
slice-by-slice.

 - David


On 4/21/07, Wagner Sales <wsalles2003 at yahoo.com.br> wrote:
>
> Hi all,
>
> I'm extracting slices from a DICOM dataset and writing on disk. The aproach
> are following:
> - Load using vtkDICOMImageReader;
> - Extract slices using vtkImageReslice.
> - Write using vtkPNGImageWriter
>
> -- CODE:
>  m_Reslicer->SetInput(m_ImageData);
>      m_Reslicer->SetInterpolationModeToLinear();
>      double minSpacing = fabs(spacing[0]);
>      if (fabs(spacing[1]) < minSpacing)
>      {
>      minSpacing = fabs(spacing[1]);
>      }
>      if (fabs(spacing[2]) < minSpacing)
>      {
>      minSpacing = fabs(spacing[2]);
>      }
>      m_Reslicer->SetOutputSpacing(minSpacing, minSpacing,
> minSpacing);
>      m_Reslicer->GetOutput()->UpdateInformation();
>      m_Reslicer->SetOutputDimensionality(2);
>        m_Reslicer->SetResliceAxes(m_Matrix);
>      m_Reslicer->GetOutput()->UpdateInformation();
>      double point[4];
>      double temp[4];
>      point[0] = 0.0;
>      point[1] = 0.0;
>      switch(m_Axy)
>      {
>          case VolumeRepresentation::Coronal:
>              point[2] =
> m_Reslicer->GetOutput()->GetSpacing()[0] * 0.5 // what's
> are the factor?;
>                break;
>          case VolumeRepresentation::Saggital:
>              point[2] =
> m_Reslicer->GetOutput()->GetSpacing()[1] * 0.5 // what's
> are the factor?;
>              break;
>          case VolumeRepresentation::Transversal:
>              point[2] =
> m_Reslicer->GetOutput()->GetSpacing()[2];
>              break;
>      }
>      vtkMatrix4x4 *matrix = m_Reslicer->GetResliceAxes();
>      point[3] = 1.0;
>          matrix->MultiplyPoint(point, temp);
>          matrix->SetElement(0, 3, temp[0]);
>          matrix->SetElement(1, 3, temp[1]);
>          matrix->SetElement(2, 3, temp[2]);
>      m_Reslicer->Update();
>      m_Slice->DeepCopy(m_Reslicer->GetOutput());
>      return m_Slice;
>
>
> When I extract slices from the transversal axis, all are extracted ok, but
> when I extract from coronal and sagittal axis, a lot of slices are empty.
> After some playing, I was discovered that's my error are these lines:
>
>     point[2] = m_Reslicer->GetOutput()->GetSpacing()[];
>
> Then I was multiplied, when extracting coronal or sagittal slices, like
> showed in the code.
> Works fine! No empty slices anymore! But, the factor are fixed, and I don't
> know how to calculate the factor 0.5.
> I'm completely wrong? Someone can help?
>
> Thks in advance,
>
> Wagner Sales
>
>
>
>
>
> __________________________________________________
> Fale com seus amigos de graça com o novo Yahoo! Messenger
> http://br.messenger.yahoo.com/
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



More information about the vtkusers mailing list