Applying LUT on a cv::Mat

I’m trying to apply a LUT on a cv::Mat image.
I read the documentation for cv::LUT here OpenCV: Operations on arrays but I don’t understand what “look-up table of 256 elements;” means: Is it that the LUT can have maximum 256 segmentations?

What format should the InputArray have?(values of 0-1, 0-255?)

Is there any example that can you point me to?

Thank you!

single channel, uchar [0…255].
think of each entry as an index into the table.
one application of it is ‘color mapping’, where you map grayscale[0…255] values to (false) colors, e.g. a heatmap

yes, exactly.

Thanks, so the cv::LUT function is channel independent. It cannot apply complicated luts that need trilinear interpolation.
I’m wonder if I can achieve this using cv::cuda::LookUpTable.

maybe explain, what you need in greater detail ?

I need to apply a lut that I take from a .cube file to a cv::Mat.

From what I tested and from what I understand cv::LUT is cahnnel independent which means that it transforms the value in a channel independent of the other 2 channels.
For example the value 23 of the R channel will always map to x no matter of the values of G and B.

The steps for applying a more complex LUT are:
For each pixel:

  1. Search the closest points in the LUT(the result will be 8 points that form a parallelepiped)
  2. Do trilinear interpolation between the points found which will result in the new pixel value.

I’m searching for ways to implement this with functions that already exist.

I hope that it is more clear now and thank you for looking into this.

1 Like

there has been discussion of “cube” files in this forum before. you might find inspiration in there.

I could not find any such post, the best solution that I found was to use an OpenGL shader. I took into consideration using CUDA, but I needed something cross platform.
It was more complicated than I expected, if anyone knows a better solution, I would be curious to learn it.