|
Using vtkImageViewer2 for DICOM Visualization |
|
|
|
|
Written by Mark Wyszomierski
|
|
Friday, 31 August 2007 |
Download article attachment: DevSample_DisplayDICOMImage.zip(14.3kb)
This sample shows the very basics up setting up vtkImageViewer2 to visualize a DICOM image.
The vtkImageViewer2 class is a nice wrapper which handles displaying a single image at a time. It supports fast zooming, panning, and window/level operations. It also has convenience methods for displaying different images in a volume.
At the time of writing, this wrapper does not support displaying true color images, rather you need to set a color map to achieve this effect (or you can extend VTK a bit to get it to work).
There's not much to this sample since vtkImageViewer2 encapsulates so much functionality. All that's really needed to visualize an image is:
- An Instance of vtkImageViewer2
- A vtkRenderWindowInteractor
- Some image data to render in a vtkImageData instance
So our tasks are to hook up our own interactor to the image viewer like so:
Connect interactor to image viewer
-
m_pImageViewer->SetupInteractor(m_pIren); We need to give the viewer some vtkImageData as input. In the sample application, we just read all DICOM images in the user specified directory.
Give image viewer some vtkImageData as input
-
m_pImageViewer->SetInput(pDICOMReader->GetOutput()); The viewer class can handle a vtkImageData instance which is actually a multi-slice volume. By default it will render only the first slice. You can use vtkImageViewer2::SetSlice() to choose which slice you want to visualize (more on this in subsequent articles).
The last tasks are to choose an initial window/level for the image viewer, and then to reset the camera so the user seees the image centered in the render window.
Set initial window/level, center the camera
-
// Set an initial window that makes sense for you.
-
m_pImageViewer->SetColorWindow(255);
-
-
// Set an initial level that makes sense for you.
-
m_pImageViewer->SetColorLevel(128);
-
-
// Reset the camera.
-
m_pImageViewer->GetRenderer()->ResetCamera();
The initial window/level value depends on the scalar values within your image. A typical (but by no means fool-proof) default is (max-min) for the window, and (max-min)/2 for the level.
When you start the sample, the image will be rendered. If all you see if a black window, it probably means that your window/level values are incorrectly so your pixel values are being masked out. Try holding the left mouse button down and moving it around to alter the window/level until you can see your image.
The attached sample was built under visual studio 2005 using C++ but the source files should be cross platform.
|