# Issue when applying vtkLookupTable

**URL:** <https://discourse.vtk.org/t/issue-when-applying-vtklookuptable/12402>\
**Category:** Development\
**Created:** [October 2, 2023, 9:33pm UTC](https://discourse.vtk.org/t/issue-when-applying-vtklookuptable/12402 "2023-10-02T21:33:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eightysix](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/e/ecccb3/32.png) [@eightysix](https://discourse.vtk.org/u/eightysix)\
**Post date:** [October 2, 2023, 9:33pm UTC](https://discourse.vtk.org/t/issue-when-applying-vtklookuptable/12402/1 "2023-10-02T21:33:23Z")

</div>

I’m applying a `vtkLookupTable` via `vtkImageSlice->GetProperty()->SetLookupTable(lut)`:

```auto
lut->SetNumberOfColors(256);
lut->SetValueRange(0, 255);
lut->SetRange(0, 255);
lut->SetNumberOfTableValues(256);
        
for (int i = 0; i <= 255; i++) {
    double red = [[parsedTable Red][i] doubleValue];
    double green = [[parsedTable Green][i] doubleValue];
    double blue = [[parsedTable Blue][i] doubleValue];
            
    lut->SetTableValue(i, red, green, blue);
}

```

I’ve fetched a set of lookup tables from [here](https://github.com/horosproject/horos/tree/horos/Horos/Resources/CLUTs) that I’ve parsed to obtain their RGB values, but when I apply them to my pipeline the result is different from Horos and other viewers (first picture is the expected result, second one is what I’m getting).

![Expected](https://discourse.vtk.org/uploads/default/original/2X/6/665ab1574f6ba94f62c7104d46c579b22f8c0eae.png)  
 ![Result](https://discourse.vtk.org/uploads/default/original/2X/1/148666f8be7b509e7cfabce41dd273ccc5c29b65.png)

Is there some obvious mistake in my code that I’m missing, or are there any settings I can tweak to achieve the expected result?

---

<div class="post-metadata">

**Author:** ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)\
**Post date:** [October 2, 2023, 10:17pm UTC](https://discourse.vtk.org/t/issue-when-applying-vtklookuptable/12402/2 "2023-10-02T22:17:18Z")

</div>

Make sure that the values for `SetTableValue()` are between zero and one.  
You might have to divide the Horos values by 255 before you use them with VTK:

```
red /= 255.0;
green /= 255.0;
blue /= 255.0;

```

---

<div class="post-metadata">

**Author:** ![eightysix](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/e/ecccb3/32.png) [@eightysix](https://discourse.vtk.org/u/eightysix)\
**Post date:** [October 2, 2023, 10:55pm UTC](https://discourse.vtk.org/t/issue-when-applying-vtklookuptable/12402/3 "2023-10-02T22:55:53Z")

</div>

Thank you for the quick reply! Your solution worked perfectly.
