[vtkusers] Convert grayscale image to rgb

David Gobbi david.gobbi at gmail.com
Sat May 31 12:11:56 EDT 2014


You might have to tell scalarsToColors what the range of your
data is, before you use the colorMapper:

scalarsToColors->SetRange(imageData->GetScalarRange());


On Sat, May 31, 2014 at 9:58 AM, Milan Vidakovic <milan.vidakovic at tp.rs> wrote:
> Thank you for a quick response. I did try it, and the scalar space does
> increase to rgb, but my output is completely black. My vtkScalarsToColors
> might be lacking something. The code is:
>
> vtkSmartPointer<vtkScalarsToColors> scalarsToColors =
> vtkSmartPointer<vtkScalarsToColors>::New();
>
> vtkSmartPointer<vtkImageMapToColors> colorMapper =
> vtkSmartPointer<vtkImageMapToColors>::New();
> firstColorMapper->SetOutputFormatToRGB();
> firstColorMapper->SetInputData(myImageVtkImageData);
> firstColorMapper->SetLookupTable( scalarsToColors );
>
>
> On Sat, May 31, 2014 at 5:44 PM, David Gobbi <david.gobbi at gmail.com> wrote:
>>
>> Use vtkImageMapToColors, here is a python example of
>> how to set it up:
>>
>> rgbConverter = vtkImageMapToColors()
>> rgbConverter.SetOutputFormatToRGB()
>> rgbConverter.SetLookupTable(vtkScalarsToColors())
>>
>> The "vtkScalarsToColors" object describes how the
>> mapping of scalars to colors is done.  By default, it just
>> replicates the scalar into the r, g, and b components.
>>
>>   David
>>
>>
>> On Sat, May 31, 2014 at 9:21 AM, Milan Vidakovic <milan.vidakovic at tp.rs>
>> wrote:
>> > I have a number of single-scalar grayscale vtkImageData objects that
>> > would
>> > need to convert to rgb. Is there a way to perform this transformation
>> > without loosing the grayscale information? Even a change from grayscale
>> > to
>> > mono-color would do the trick.
>> >
>> > Thank you!
>> > Milan


More information about the vtkusers mailing list