[vtkusers] How to display dicom images without scaling?
Joseph D. Wieber Jr.
jdwieber at gmail.com
Sun Jul 24 15:50:03 EDT 2011
Hello,
I'm new to VTK and I'm working on a project that reads dicom image
files. The files I have are 512x512 pixels, but when I view them they
display at approx 150x150 pixels. I'm using Qt to create the UI via Qt
designer with the qvtkWidget. I'm using the vtkImageViewer2 class to
handle the visualization. I pasted my initialization code below. The
algorithm I'm working on is intelligent scissors (user guided
segmentation). I originally implemented it in OpenCV, but need to
convert my app. to use VTK. I need to extract pixel locations from left
click and mouse over events, and I have this part working correctly.
However, for the algorithm to work properly I need to do a lookup into a
cost table based on pixel location. The cost table is built to the
correct size (512x512), and when I write out the dimensions of the image
I see 512x512, but when I do the picking I get locations in the range of
0 - 150. Indeed, the displayed image takes up only a small portion of
the widget (see image below). I tried searching the web and the mailing
list, but found nothing. I'm not sure what search terms are
appropriate. I found in the vtkImageViewer2 documentation that dicom
images are scaled by Z coordinate of the image slice. When I print out
the position of the image the z coord is 0, but I don't know what (or
how to get) the position of the camera is. How can I make the
visualization pipeline display the image at full size?
Thank you in advance for any help or suggestions.
Regards,
Joseph.
MainWindow::MainWindow( QWidget *parent, const string& fname ) :
QMainWindow( parent ),
ui( new Ui::MainWindow ),
m_fileName( fname )
{
ui->setupUi( this );
// Read the image
vtkSmartPointer< vtkDICOMImageReader > reader =
vtkSmartPointer< vtkDICOMImageReader >::New();
reader->SetFileName( m_fileName.c_str () );
reader->Update ();
// setup the intelligent scissors object
//mexican hat LoG
double laplacian[] = { 0., 0., -1., 0., 0.,
0., -1., -2., -1., 0.,
-1., -2., 16., -2., -1.,
0., -1., -2., -1., 0.,
0., 0., -1., 0., 0. };
m_spScissors.reset( new IntelligentScissors( reader->GetOutput (),
laplacian ) );
// Setup the blending function to overlay the segmentation contour
on the image
vtkSmartPointer< vtkImageBlend > blend =
vtkSmartPointer< vtkImageBlend >::New();
blend->AddInputConnection( reader->GetOutputPort() );
blend->SetOpacity( 0, 0.6 );
blend->AddInputConnection( m_spScissors->getPathImage () );
blend->SetOpacity( 1, 0.4 );
vtkSmartPointer< vtkImageViewer2 > viewer =
vtkSmartPointer< vtkImageViewer2 >::New();
viewer->SetInputConnection ( blend->GetOutputPort () );
// make the viewer use the interactor supplied from the qvtk widget
viewer->SetupInteractor ( ui->qvtkWidget->GetInteractor () );
//bind Qt and VTK
ui->qvtkWidget->SetRenderWindow ( viewer->GetRenderWindow () );
//try to get image displayed at full size
viewer->GetInteractorStyle ()->AutoAdjustCameraClippingRangeOff ();
// Annotate the image with mouse over pixel information
vtkSmartPointer< vtkCornerAnnotation > cornerAnnotation =
vtkSmartPointer< vtkCornerAnnotation >::New();
cornerAnnotation->SetLinearFontScaleFactor( 2 );
cornerAnnotation->SetNonlinearFontScaleFactor( 1 );
cornerAnnotation->SetMaximumFontSize( 15 );
cornerAnnotation->SetText( 0, "Off Image" );
cornerAnnotation->SetText( 3, "<window>\n<level>" );
cornerAnnotation->GetTextProperty()->SetColor( 1, 0, 0 );
viewer->GetRenderer ()->AddViewProp ( cornerAnnotation );
// Picker to pick pixels
vtkSmartPointer< vtkPropPicker > propPicker =
vtkSmartPointer< vtkPropPicker >::New();
propPicker->PickFromListOn();
// Give the picker a prop to pick
vtkImageActor* imageActor = viewer->GetImageActor();
propPicker->AddPickList( imageActor );
// disable interpolation, so we can see each pixel
imageActor->InterpolateOff();
// Set callback functions
vtkInteractorStyleImage* imageStyle = viewer->GetInteractorStyle();
//listen to MouseMoveEvents invoked by the interactor's style
OnMouseMovePtr onMouseMove = OnMouseMovePtr::New();
onMouseMove->SetViewer( viewer );
onMouseMove->SetAnnotation( cornerAnnotation );
onMouseMove->SetPicker( propPicker );
onMouseMove->SetIntelligentScissors ( m_spScissors );
imageStyle->AddObserver( vtkCommand::MouseMoveEvent, onMouseMove );
//listen to LeftButtonPressEvent invoked by the interactor's style
OnLeftClickPtr onLeftClick = OnLeftClickPtr::New ();
onLeftClick->SetViewer ( viewer );
onLeftClick->SetAnnotation ( cornerAnnotation );
onLeftClick->SetPicker ( propPicker );
onLeftClick->SetIntelligentScissors ( m_spScissors );
imageStyle->AddObserver ( vtkCommand::LeftButtonPressEvent,
onLeftClick );
viewer->Render ();
}
View in HTML to see image
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110724/ef8c5dc3/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SummerIS.png
Type: image/png
Size: 50701 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110724/ef8c5dc3/attachment.png>
More information about the vtkusers
mailing list