[vtkusers] DICOM images flipped ITK-VTK

Bill Lorensen bill.lorensen at gmail.com
Sun Feb 27 16:03:44 EST 2011


This is a common problem. VTK and ITK use different conventions. ITK
uses image convention where the first pixel in memory if shown in the
upper left of the displayed image. VTK uses computer graphics
convention where the first pixel in memory is shown in the lower left
of the displayed image.

The ITK convention conforms to radiology convention.

You can use vtkImageFlip to flip the vtk images about the y axis.

There are other differences. VTK images do not honor the orientation
of DICOM images while ITK images do.

Bill

On Sun, Feb 27, 2011 at 2:45 PM, Darshan Pai <darshanpai at gmail.com> wrote:
> When I used VTKDICOMReader directly on a axial slice data I get the right
> answer in radiological convention. But using the same data in ITK gives me
> an orientation mismatch error . But anyway you can just use vtkImageFlip or
> just multiple the necessary rotation matrix to the direction cosines.
>
> Regards
> Darshan
>
> On Sun, Feb 27, 2011 at 12:59 PM, Alexander Taghva <alextaghva at gmail.com>
> wrote:
>>
>> Hello,
>> I am relatively new to ITK and VTK.  I am trying to read a DICOM series
>> into ITK and display it with a simple viewer using VTK and KWWidgets.  When
>> I load the series in ITK, the axial images are upside-down and the sagittal
>> images are flipped left-right.    If I try doing it all in VTK
>> (vtkDicomImageReader), the sagittal and coronal images are upside-down.  I
>> have seen this issue touched on before, but I couldn't find a good solution.
>> Key parts of my code are below.  I am using ITK 3.20 and VTK 5.6.1 on Ubuntu
>> Linux 10.10.
>>
>> ******************************
>>
>> **********************************************************************************************************************
>>
>>     // initialize ITK DICOM reader
>>     typedef unsigned short PixelType;
>>     const unsigned int Dimension = 3;
>>
>>     typedef itk::Image<PixelType, Dimension> ImageType;
>>     typedef itk::ImageSeriesReader< ImageType > ReaderType;
>>     ReaderType::Pointer reader = ReaderType::New();
>>
>>
>>
>>     typedef itk::GDCMImageIO ImageIOType;
>>     ImageIOType::Pointer dicomIO = ImageIOType::New();
>>     reader->SetImageIO( dicomIO );
>>
>>     typedef itk::GDCMSeriesFileNames NamesGeneratorType;
>>     NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
>>     nameGenerator->SetUseSeriesDetails( true );
>>     nameGenerator->SetInputDirectory( "DICOM" );
>>     const ReaderType::FileNamesContainer & filenames =
>> nameGenerator->GetInputFileNames();
>>
>>     reader->SetFileNames( filenames );
>>
>>     try
>>     {
>>     reader->Update();
>>     }
>>     catch (itk::ExceptionObject &ex)
>>     {
>>     std::cout << ex << std::endl;
>>     return EXIT_FAILURE;
>>     }
>>
>>    // now connect to VTK
>>     typedef itk::ImageToVTKImageFilter< ImageType> ConnectorType;
>>     ConnectorType::Pointer connector = ConnectorType::New();
>>     connector->SetInput( reader->GetOutput() );
>>
>>      vtkImageViewer2     *viewer = vtkImageViewer2::New();
>>
>>     //Create a VTK image viewer, set it up so that it uses our render
>> widget, set its input to the output of the reader, reset the camera to
>> center the whole slice
>>     viewer->SetRenderWindow(rw->GetRenderWindow());
>>     viewer->SetRenderer(rw->GetRenderer());
>>     viewer->SetInput(connector->GetOutput());
>>     viewer->SetupInteractor(rw->GetRenderWindow()->GetInteractor());
>>     rw->ResetCamera();
>>
>>     //Retrieve the corner annotation object from the render widget, point
>> it to the viewer actor and window/level filter, and let it display both
>> slice and window/level in different corners using tags
>>     vtkCornerAnnotation *ca = rw->GetCornerAnnotation();
>>     ca->SetImageActor(viewer->GetImageActor());
>>     ca->SetWindowLevel(viewer->GetWindowLevel());
>>     ca->SetText(2,"<slice>");
>>     ca->SetText(3,"<window>\n<level>");
>>
>>     //Create a scale object in our window, set its range to match the
>> number of slices, set its callback to use its value to set the slice in the
>> viewer, pack the scale in our window below the render widget
>>     vtkKWScale *slice_scale = vtkKWScale::New();
>>     slice_scale->SetParent(win->GetViewFrame());
>>     slice_scale->Create();
>>     slice_scale->SetRange(viewer->GetSliceMin(),viewer->GetSliceMax());
>>     slice_scale->SetCommand(viewer, "SetSlice");
>>     app->Script("pack %s -side top -expand n -fill x",
>> slice_scale->GetWidgetName());
>>
>>
>>
>> ******************************************************************************************************************************************************
>>
>> Alex
>>
>> _______________________________________________
>> 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://www.vtk.org/mailman/listinfo/vtkusers
>>
>
>
> _______________________________________________
> 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://www.vtk.org/mailman/listinfo/vtkusers
>
>



More information about the vtkusers mailing list