[vtkusers] RGBA to gray in VTK

Prathamesh Kulkarni prathameshmkulkarni at gmail.com
Wed Jul 21 16:36:50 EDT 2010


Thanks! Here is what I did:

    int channels_before_component_filter =
RGBA_image_data->GetNumberOfScalarComponents(); //4

    vtkSmartPointer<vtkImageExtractComponents> component_extractor =
vtkSmartPointer<vtkImageExtractComponents>::New();
    component_extractor->SetInput(RGBA_image_data);
    component_extractor->SetComponents(0, 1, 2);
    component_extractor->Update();

    int channels_before_luminance_filter =
component_extractor->GetOutput()->GetNumberOfScalarComponents(); //3

    vtkSmartPointer<vtkImageLuminance> luminance_filter =
vtkSmartPointer<vtkImageLuminance>::New();
    luminance_filter->SetInput(component_extractor->GetOutput());
    luminance_filter->Update();

    int channels_after_luminance_filter =
luminance_filter->GetOutput()->GetNumberOfScalarComponents(); //1


Prathamesh

On Wed, Jul 21, 2010 at 3:12 PM, David Doria
<daviddoria+vtk at gmail.com<daviddoria%2Bvtk at gmail.com>
> wrote:

> On Wed, Jul 21, 2010 at 4:09 PM, David Gobbi <david.gobbi at gmail.com>
> wrote:
> > You need to be careful here.  There are two ways to convert images to
> greyscale:
> >
> >  vtkImageLuminance -> use luminance equation for properly weighting
> > the R, G, and B
> >
> >  vtkImageMagnitude -> do a sum-of-squares computation
> >
> > These filters are meant for different things.  For RGB, you usually
> > want to use luminance because in the RGB colorspace, G has slightly
> > higher luminance than R, and both have much higher luminance than B.
> >
> > The vtkImageMagnitude filter is meant for use on vector images, not so
> > much for RGB images.
> >
> > You can use vtkImageExtractComponents to extract the RGB components
> > from an RGBA image:
> > vtkImageExtractComponents::SetComponents(0, 1, 2);
> >
> >  David
>
> Here are examples of what David G. said:
>
> http://www.vtk.org/Wiki/VTK/Examples/Images/ImageLuminance
> http://www.vtk.org/Wiki/VTK/Examples/Images/ExtractComponents
>
> Thanks,
>
> David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100721/2c18b60b/attachment.htm>


More information about the vtkusers mailing list