[vtkusers] display dicom image in vtk
John Drescher
drescherjm at gmail.com
Thu Apr 2 21:51:48 EDT 2009
On Thu, Apr 2, 2009 at 9:07 PM, Hui Wang <cougarhui at yahoo.com> wrote:
> Hi, all
>
> I am new to vtk and want to read a dicom image from file and display it in a
> Qt GUI using qvtkWidget.
>
> I used vtkDICOMImageReader to read the image, but when I used vtkImageViewer
> to display, it will show in another window, instead of qvtkWidget.
>
> So I tried vtkImageActor, vtkRenderer and vtkRendererWindow pipeline, but an
> error happened saying
>
> ERROR: In /home/mandrake/rpm/BUILD/VTK/Rendering/vtkImageActor.cxx, line
> 182
> vtkOpenGLImageActor (0x10ed8b0): This filter requires unsigned char scalars
> as input
>
> Then I tried vtkImageCast, but the displayed image is not correct. Does
> anybody know the reason and how to fix it? Thanks a lot.
>
> Hui Wang
>
>
> The following is the code I used:
>
> vtkDICOMImageReader *reader = vtkDICOMImageReader::New();
> reader->SetFileName(argv[1]);
>
> vtkImageCast *cast = vtkImageCast::New();
> cast->SetInputConnection(reader->GetOutputPort());
> cast->SetOutputScalarTypeToUnsignedChar();
>
> vtkImageActor *actor = vtkImageActor::New();
> actor->SetInput(cast->GetOutput());
>
> vtkRenderer *render = vtkRenderer::New();
> render->AddActor(actor);
> render->ResetCamera();
>
> vtkRenderWindow *window = vtkRenderWindow::New();
> window->AddRenderer(render);
>
> window->Render();
>
>
>
Try the vtkImageMapToWindowLevelColors instead. You will most likely
need to do that anyways.
John
More information about the vtkusers
mailing list