[vtkusers] vtkDICOMImageReader origin

David Gobbi david.gobbi at gmail.com
Mon May 11 10:32:38 EDT 2015


Hi Davis,

The vtkDICOMImageReader doesn't set the Origin.  In any case, the VTK
"Origin" and the ITK "Origin" have slightly different definitions, because
in ITK the origin takes the image orientation into account.

The best you can do is call GetImagePositionPatient() and
GetImageOrientationPatient() on the reader, and use the results to position
and orient the image.

I've written my own dicom reader (https://github.com/dgobbi/vtk-dicom) that
provides a GetPatientMatrix() method to return the position/orientation as
a vtkMatrix4x4.

 - David

On Mon, May 11, 2015 at 7:11 AM, DVigneault <davis.vigneault at gmail.com>
wrote:

> All--
>
> I'm having a problem where vtkDICOMImageReader is (incorrectly) giving an
> origin of zero.  I have two programs (code below) to read in the image and
> print out the dimension/spacing/origin--the first with ITK, the second with
> VTK.  The two programs give the same dimension and spacing, but the ITK
> program gives a nonzero origin and the VTK program gives a zero origin. The
> two programs are reading the same dataset.  Am I misusing the
> vtkDICOMImageReader somehow?  Has anyone come across this before?
>
> Best, and thanks,
>
> --Davis
>
> //
> // VTK
> //
>
> #include "vtkSmartPointer.h"
> #include "vtkDICOMImageReader.h"
> #include "vtkImageData.h"
>
> int main(int argc, char ** argv)
> {
>
>   vtkSmartPointer< vtkDICOMImageReader > reader =
>     vtkSmartPointer< vtkDICOMImageReader >::New();
>   reader->SetDirectoryName("../../data/ct_heart");
>   reader->Update();
>
>   vtkSmartPointer<vtkImageData> data =
>     vtkSmartPointer<vtkImageData>::New();
>   data = reader->GetOutput();
>
>   int dims[3];
>   data->GetDimensions(dims);
>
>   double spacing[3];
>   data->GetSpacing(spacing);
>
>   double origin[3];
>   data->GetOrigin(origin);
>
>   std::cout << "Dimensions: [" << dims[0] << ", " << dims[1] << ", " <<
> dims[2] << "]" << std::endl;
>   std::cout << "Spacing: [" << spacing[0] << ", " << spacing[1] << ", " <<
> spacing[2] << "]" << std::endl;
>   std::cout << "Origin: [" << origin[0] << ", " << origin[1] << ", " <<
> origin[2] << "]" << std::endl;
>
> // Output:
> // Dimensions: [512, 512, 120]
> // Spacing: [0.332, 0.332, 1]
> // Origin: [0, 0, 0]
>
>
>   return EXIT_SUCCESS;
> }
>
> //
> // ITK
> //
>
> #include "itkImage.h"
> #include "itkGDCMImageIO.h"
> #include "itkGDCMSeriesFileNames.h"
> #include "itkImageSeriesReader.h"
>
> typedef itk::Image< short, 3 >   TInImage;
> typedef itk::GDCMImageIO                              TImageIO;
> typedef itk::GDCMSeriesFileNames                      TImageNames;
> typedef itk::ImageSeriesReader< TInImage >            TImageReader;
>
> int main( int argc, char* argv[] )
> {
>
>   TImageIO::Pointer dicomIO = TImageIO::New();
>
>   TImageNames::Pointer names = TImageNames::New();
>   names->SetInputDirectory( "../../data/ct_heart" );
>
>   TImageReader::Pointer imageReader = TImageReader::New();
>   imageReader->SetImageIO( dicomIO );
>   imageReader->SetFileNames( names->GetInputFileNames() );
>   imageReader->Update();
>
>   std::cout << "Dimensions: " <<
> imageReader->GetOutput()->GetLargestPossibleRegion().GetSize() <<
> std::endl;
>   std::cout << "Spacing: " << imageReader->GetOutput()->GetSpacing() <<
> std::endl;
>   std::cout << "Origin: " << imageReader->GetOutput()->GetOrigin() <<
> std::endl;
>
> // Output:
> // Dimensions: [512, 512, 120]
> // Spacing: [0.332, 0.332, 1]
> // Origin: [-71.084, -93.584, 1562.5]
>
>   return EXIT_SUCCESS;
>
> }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150511/17c6cf19/attachment.html>


More information about the vtkusers mailing list