[vtk-developers] Incorrect color function in vtkImageMapToWindowLevelColors with lookupTable

David Gobbi david.gobbi at gmail.com
Fri May 25 15:07:55 EDT 2018


I'm going to try to answer my own question, hopefully someone
will jump in and correct me if I am wrong.

The idea behind vtkImageMapToWindowLevelColors seems to
be that the vtkLookupTable is intended to map the input values
to different hues (using whatever Range was specified), and
then the Window/Level is used to adjust the luminance.

My own typical use of VTK is medical image display, using
16-bit input images.  So I want the window/level to be applied
directly to the 16-bit values.  I definitely do not want to convert
my 16-bit values to 8-bit, and then rescale each 8-bit value
according to where the 16-bit value sits in the Window/Level.
But this seems to be what vtkImageMapToWindowLevelColors
does.

 - David


On Fri, May 25, 2018 at 12:02 PM, David Gobbi <david.gobbi at gmail.com> wrote:

> Hi xVict,
>
> I've never trusted that code either, a per-component shift and scale only
> makes sense to me if the input data is RGB.  I don't understand why
> this class applies per-component shift and scale after vtkLookupTable.
>
> Can anyone explain what's going on in this code?
>
>  - David
>
>
> On Fri, May 25, 2018 at 8:53 AM, xVict <suharev at roentgenprom.ru> wrote:
>
>> Hi David!
>>
>> Some code skeleton:
>> // Image viewer creation
>>     this->imgViewer       = vtkSmartPointer<vtkImageViewer2>::New();
>>
>> // Lut creation
>>     if (colorLut == nullptr)
>>         colorLut = vtkSmartPointer<vtkLookupTable>::New();
>>     int norm = Range[1] - Range[0] + 1;
>>     colorLut->SetRange(Range[0], Range[1]);
>>     colorLut->SetIndexedLookup(0);
>>     colorLut->SetNumberOfTableValues(norm);
>>     colorLut->Build();
>>     for (int i = 0; i < norm; i++) {
>>       double cl = double(i) / (norm - 1);
>>       colorLut->SetTableValue(i, cl, cl, cl);
>>     }
>>
>> // change view option
>>         double c = 0.5*(this->Range[1] + this->Range[0]);
>>         double w = 1.0*(this->Range[1] - this->Range[0]);
>>         this->imgViewer->GetWindowLevel()->SetLevel(c);
>>         this->imgViewer->GetWindowLevel()->SetWindow(w);
>>         if (this->optycaltype == PSEUDO_COLOR) {
>>             createPseudoLUT();
>>             if (this->imgViewer->GetWindowLevel()->GetLookupTable() ==
>> nullptr)
>>                 this->imgViewer->GetWindowLeve
>> l()->SetLookupTable(colorLut);
>>         }
>>         else {
>>             if (this->imgViewer->GetWindowLevel()->GetLookupTable() !=
>> nullptr)
>>                 this->imgViewer->GetWindowLeve
>> l()->SetLookupTable(nullptr);
>>         }
>>         if (this->source != nullptr)
>>             imgViewer->Render();
>>
>> For 16bit image this code should show identical picture. But for
>> PSEUDO_COLOR==8bit-gray (r=g=b in range [0...1] == [0...255]).
>>
>> Sincerely, Victor.
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtk-developers/attachments/20180525/a6c2a2f3/attachment.html>


More information about the vtk-developers mailing list