[vtkusers] Correct coordinate transformations for DICOM data set.

David Gobbi david.gobbi at gmail.com
Wed Aug 20 13:24:19 EDT 2014


Just to be complete, here is a code block that includes a filter
that forces the Origin to be (0,0,0), so that all positioning is done
by the matrix:

  vtkSmartPointer<vtkDICOMImageReader> reader =
    vtkSmartPointer<vtkDICOMImageReader>::New();
  reader->SetDirectoryName(directoryName);

  // flip the image in Y and Z directions
  vtkSmartPointer<vtkImageReslice> flip =
    vtkSmartPointer<vtkImageReslice>::New();
  flip->SetInputConnection(reader->GetOutputPort());
  flip->SetResliceAxesDirectionCosines(
    1,0,0, 0,-1,0, 0,0,-1);

  // force the origin to be (0,0,0) since we set position in the matrix
  vtkSmartPointer<vtkImageChangeInformation> change =
    vtkSmartPointer<vtkImageChangeInformation>::New();
  change->SetInputConnection(flip->GetOutputPort());
  change->SetOutputOrigin(0,0,0);

  change->Update();
  vtkSmartPointer<vtkImageData> image = change->GetOutput();

  // generate the matrix
  float *position = reader->GetImagePositionPatient();
  float *orientation = reader->GetImageOrientationPatient();
  float *xdir = &orientation[0];
  float *ydir = &orientation[3];
  float zdir[3];
  vtkMath::Cross(xdir, ydir, zdir);

  vtkSmartPointer<vtkMatrix4x4> matrix =
    vtkSmartPointer<vtkMatrix4x4>::New();
  for (int i = 0; i < 3; i++)
    {
    matrix->Element[i][0] = xdir[i];
    matrix->Element[i][1] = ydir[i];
    matrix->Element[i][2] = zdir[i];
    matrix->Element[i][3] = position[i];
    }

Definitely this is a lot of work just to read a DICOM image in the
correct coordinate system!  Let me know if this gives you the
results that you need.

 - David

On Wed, Aug 20, 2014 at 11:21 AM, Vipul Pai Raikar <vpai at g.clemson.edu> wrote:
> Thank you for your prompt and detailed response Dr Gobbi. I was just about to
> ask you about the origin. I shall try and implement these ideas and get
> back.
>
> Thank you very much!
>
> V
>
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/Correct-coordinate-transformations-for-DICOM-data-set-tp5728309p5728313.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers


More information about the vtkusers mailing list