[vtkusers] simple vtkLookupTable question

Cory Quammen cory.quammen at kitware.com
Tue Oct 27 12:31:51 EDT 2015


That works too :-)

On Tue, Oct 27, 2015 at 12:17 PM, Richard Brown <richard.j.brown at live.co.uk>
wrote:

> Cory,
>
> Thanks for the help.
>
> Found a long-winded way a few days ago, which would work for any colour
> lookup table that exists in imageJ.
>
> In case this helps anyone in the future, here’s what I did:
>
> In ImageJ,
> Image -> LookupTables -> Fire
> Image -> Color -> Show LUT -> List
>
> The list is of the form:
> index, R, G, B
> where RGB are 0 to 255. vtkLookupTable expects RGB between 0 and 1 so
> divide by 255 in the code
>
> With a little bit of copy and paste jiggerypokery for the
> SetTableValue(index,R,G,B), the vtkLookupTable then looks as follows:
>
>         vtkSmartPointer<vtkLookupTable> l_p_fireLookupTable = vtkSmartPointer<vtkLookupTable>::New();
>
>
>         if (a_cutoffLimit == -1) l_p_fireLookupTable->SetRange(a_low, a_high);
>
>         else l_p_fireLookupTable->SetRange(a_low, a_cutoffLimit);
>
>
>         l_p_fireLookupTable->SetNumberOfColors(256);
>
>
>         l_p_fireLookupTable->SetTableValue(0, 0./255., 0./255., 0./255.);
>
>         l_p_fireLookupTable->SetTableValue(1, 0./255., 0./255., 7./255.);
>
>         l_p_fireLookupTable->SetTableValue(2, 0./255., 0./255., 15./255.);
>
>         l_p_fireLookupTable->SetTableValue(3, 0./255., 0./255., 22./255.);
>
>         			...
>
> 	l_p_fireLookupTable->SetTableValue(253, 255./255., 255./255., 255./255.);
>
>         l_p_fireLookupTable->SetTableValue(254, 255./255., 255./255., 255./255.);
>
>         l_p_fireLookupTable->SetTableValue(255, 255./255., 255./255., 255./255.);
>
>
>         l_p_fireLookupTable->Build();
>
>
> Richard
>
> On 27 Oct 2015, at 16:15, Cory Quammen <cory.quammen at kitware.com> wrote:
>
> Richard,
>
> It's actually a little bit involved.
>
> Here's Python code to generate ParaView's Black-Body Radiation color map,
> which I think is similar to ImageJ's 'hot' lookup table.
>
> import vtk
>
> cmap = vtk.vtkDiscretizableColorTransferFunction()
> cmap.SetColorSpaceToRGB()
> cmap.AddRGBPoint(0.0, 0.0, 0.0, 0.0) # black
> cmap.AddRGBPoint(0.4, 1.0, 0.9, 0.0) # reddish
> cmap.AddRGBPoint(0.8, 0.9, 0.9, 0.0) # yellow
> cmap.AddRGBPoint(1.0, 1.0, 1.0, 1.0) # white
>
> scalarValues = vtk.vtkFloatArray()
> scalarValues.SetNumberOfComponents(1)
> scalarValues.SetNumberOfTuples(256)
> for i in xrange(256):
>     scalarValues.SetTupleValue(i, [i / 255.0])
>
> table = cmap.MapScalars(scalarValues, 0, -1)
>
> for i in xrange(table.GetNumberOfTuples()):
>     print table.GetTuple(i)
>
> Note that this defines a colormap for scalar values in the range [0, 1].
> You can rescale the first arguments to AddRGBPoints() above for a different
> scalar range.
>
> Hope that helps,
> Cory
>
> On Wed, Oct 21, 2015 at 5:22 AM, mbcx9rb9 <richard.j.brown at live.co.uk>
> wrote:
>
>> I imagine this is a very simple question, but I haven't found the answer
>> already in the group.
>>
>> I have greyscale data that I want to apply a lookup table to. Currently,
>> my
>> lowest value is red and my highest is blue, but I would like something
>> that
>> looks more like the 'fire' lookup table in imageJ.
>>
>> In essence, I think I want my lowest value to be black and my highest to
>> be
>> a red/white. Can anyone give me any pointers?
>>
>> Thanks in advance,
>> Richard Brown
>>
>>
>>
>> --
>> View this message in context:
>> http://vtk.1045678.n5.nabble.com/simple-vtkLookupTable-question-tp5734493.html
>> Sent from the VTK - Users mailing list archive at Nabble.com.
>> _______________________________________________
>> 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
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>
>
>
> --
> Cory Quammen
> R&D Engineer
> Kitware, Inc.
>
>
>


-- 
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151027/b8eee280/attachment.html>


More information about the vtkusers mailing list