[vtkusers] DICOM images flipped ITK-VTK

Alexander Taghva alextaghva at gmail.com
Sun Feb 27 12:59:06 EST 2011


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110227/d0f4da08/attachment.htm>


More information about the vtkusers mailing list