[vtkusers] how to display RGB array/image using vtkImageImport

David Gobbi david.gobbi at gmail.com
Wed Mar 5 15:07:49 EST 2008


And you might also have to set the following:

viewer->GetWindowLevel()->SetWindow(255.0);
viewer->GetWindowLevel()->SetLevel(127.5);

   David



On Wed, Mar 5, 2008 at 3:04 PM, David Gobbi <david.gobbi at gmail.com> wrote:
> Hi Elvis,
>
>  I looked at the vtkImageViewer2 code, and it creates a default color
>  table for you.  If you get rid of its color table, it should display the RGB
>  data directly.
>
>  The command to get rid of the viewer's color table is as follows:
>
>  viewer->GetWindowLevel()->SetLookupTable(0);
>
>    David
>
>
>
>
>  On Wed, Mar 5, 2008 at 2:48 PM, Elvis Chen <elvis.chen at gmail.com> wrote:
>  > hello,
>  >
>  > I'm trying to import video/still-images from an ultra-sound machine and
>  > display it using vtk.  I can grab an image from the frame-grabber and save
>  > the image as PPM (basically RGB values with some headers).  The range of the
>  > RGB is [0..255] and I know the dimension of the image.
>  >
>  > Instead of saving it to a file I want vtk to grab the array pointer and
>  > display it directly.  My code looks like:
>  >
>  >   vtkImageImport *importer = vtkImageImport::New();
>  >   importer->SetWholeExtent( 0, 719, 0, 479, 0, 0 );
>  >    importer->SetDataExtentToWholeExtent();
>  >   importer->SetDataScalarTypeToInt();
>  >   importer->SetNumberOfScalarComponents( 3 );
>  >   importer->SetImportVoidPointer( h.imageRGB );
>  >
>  >   vtkImageFlip *flip = vtkImageFlip::New();
>  >    flip->SetInputConnection( importer->GetOutputPort() );
>  >   flip->SetFilteredAxis( 1 );
>  >
>  >   vtkImageViewer2 *viewer = vtkImageViewer2::New();
>  >   viewer->SetInputConnection( flip->GetOutputPort() );
>  >    viewer->SetZSlice( 0 );
>  >
>  >
>  > where h.imageRGB is a pointer to integer array whose size is 720x480x3.  The
>  > RGB are stored as [R0 G0 B0 R1 G1 B2 ... ] in h.imageRGB.  The first pixel
>  > is on the top-left corner so I need to use vtkImageFlip to get the correct
>  > orientation.
>  >
>  > The resulting image displayed fine except for the colour.  It looks like a
>  > gray-scale image where as the original US image has come coloured region.
>  > Can someone please shed some light into what might be wrong?  Is there a
>  > function to get the range of pixel value (to 0 to 255)?
>  >
>  > Any help is very much appreciated,
>  >
>  > Elvis
>  >
>  > _______________________________________________
>  >  This is the private VTK discussion list.
>  >  Please keep messages on-topic. Check the 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