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

Elvis Chen elvis.chen at gmail.com
Wed Mar 5 14:48:45 EST 2008


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


More information about the vtkusers mailing list