[vtkusers] RGBA to gray in VTK

David Gobbi david.gobbi at gmail.com
Wed Jul 21 16:09:28 EDT 2010


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

On Wed, Jul 21, 2010 at 2:05 PM, Prathamesh Kulkarni
<prathameshmkulkarni at gmail.com> wrote:
> I have the output of vtkImageBlend which is RGBA, and I need to convert this
> to grayscale.
>
> Prathamesh
>
> On Wed, Jul 21, 2010 at 3:00 PM, David Doria <daviddoria+vtk at gmail.com>
> wrote:
>>
>> On Wed, Jul 21, 2010 at 3:51 PM, Prathamesh Kulkarni
>> <prathameshmkulkarni at gmail.com> wrote:
>> > Hello all,
>> >
>> > I am trying to convert an image from RGBA to gray scale so that I can
>> > compare it pixel by pixel with another gray scale image. Following is
>> > what I
>> > did:
>> >
>> >     vtkSmartPointer<vtkImageMapToColors> gray_from_RGBA_map =
>> > vtkSmartPointer<vtkImageMapToColors>::New();
>> >     grayd_from_RGB_map->SetInput(RGBA_image_data);
>> >
>> >     gray_from_RGB_map->SetOutputFormatToLuminance();
>> >
>> >     gray_from_RGB_map->Update();
>> >
>> >     int channels =
>> > gray_from_RGBA_map->GetOutput()->GetNumberOfScalarComponents();
>> >
>> > The variable "channels" is 4 irrespective of whether I include a
>> > vtkImageMapToColors in the pipeline.
>> >
>> > Am I doing anything wrong here? What is the best way to do this?
>> >
>> >
>> > Any help will be highly appreciated.
>> >
>> >
>> > Prathamesh
>>
>> Is the 'A' important? Or do you just want RGB to grey?
>>
>> http://www.vtk.org/Wiki/VTK/Examples/Images/ConvertToGreyScale
>>
>> Thanks,
>>
>> David
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK 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