[vtkusers] how to display RGB array/image using vtkImageImport
Karthik Krishnan
karthik.krishnan at kitware.com
Wed Mar 5 15:45:24 EST 2008
You need to set a lookup table on the vtkImageMapToWIndowLevelColors
(viewer->GetWindowLevel()) to get colors to show up.
// Something like the following should do...
imageviewer2->GetWindowLevel()->SetOutputFormatToRGB();
vtkLookupTable *lut = vtkLookupTable::New();
lut->SetHueRange(0.66667, 0.0);
lut->SetSaturationRange(1, 1);
lut->SetValueRange(1, 1);
lut->SetAlphaRange(1, 1);
lut->SetNumberOfColors(256);
lut->Build();
imageviweer2->GetWindowLevel()->SetLookupTable(lut);
-----
Or a hack to avoid settting the lookup table is...
this->ImageViewer[0]->SetColorLevel(127.50001); // minor offset from
127.5
If you dig into the sources, you'll find out why the hack works :)
bye
--
karthik
Can you offset the level a bit and test it as:
viewer->GetWindowLevel()->SetLevel( 127.501 );
Or else, you need to set a lookup table on the
vtkImageMapToWIndowLevelColors (viewer->GetWindowLevel()) to get colors to
show up.
On 3/5/08, Elvis Chen <elvis.chen at gmail.com> wrote:
>
> hi David,
>
> Thanks for the quick reply. I've put the following 3 lines into my code:
>
>
> viewer->GetWindowLevel()->SetWindow( 255.0 );
> viewer->GetWindowLevel()->SetLevel( 127.5 );
> viewer->GetWindowLevel()->SetLookupTable( 0 );
>
> (your 1st email was sent to me only, not to vtkusers), but I still only
> get black/white image. Actually, the line that nulls the lookup table
> doesn't change the grabbed image at all. Should I not use vtkImageViewer2
> at all?
>
> h.imageRGB is an int array created using "new int [ 720x480x3 ]". What
> data scalar type should I set it to?
>
> Elvis
>
>
> On Wed, Mar 5, 2008 at 3:07 PM, David Gobbi <david.gobbi at gmail.com> wrote:
>
> > 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
> > > >
> > > >
> > >
> >
>
>
> _______________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080305/fa4f1e95/attachment.htm>
More information about the vtkusers
mailing list