Below is an example of building LUT:

identity = np.arange(256, dtype = np.dtype('uint8'))
zeros = np.zeros(256, np.dtype('uint8'))
lut = np.dstack((identity, identity, zeros))

Note, there is much simpler and straightforward way zeroing the red channel:

img[:,:,2] = 0

Also calling LUT function should look like this:

dstImage = cv2.LUT(img, lut)

Set blue values greater than b_max to b_max:

b_max = 20
img[img[:,:,0] > b_max, 0] = b_max;
Answer from ivan_onys on Stack Overflow
🌐
GitHub
github.com › Milchreis › OpenCV-LUT-Editor
GitHub - Milchreis/OpenCV-LUT-Editor: Tool to create freehand color correction lookup tables for OpenCV · GitHub
Tool to create freehand color correction lookup tables for OpenCV Implemented in Processing for OpenCV and experimentational research.
Author: Milchreis
🌐
Readthedocs
opencv-laboratory.readthedocs.io › en › latest › nodes › core › LUT.html
LUT — OpenCV Laboratory 1.0 alpha documentation
OpenCV Laboratory » · core » · LUT · Edit on GitHub · Performs a look-up table transform of an array. image_in – Input array of 8-bit elements.
Discussions

python - Apply openCV Look Up Table (LUT) to an image - Stack Overflow
I want to apply a custom color look up table (LUT) on an image. I have looked over the openCV LUT Api but I can not seem to get it right. #!/bin/bash # -*- coding: utf-8 -*- import os import num... More on stackoverflow.com
🌐 stackoverflow.com
Applying LUT on a cv::Mat - C++ - OpenCV
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 maximu… More on forum.opencv.org
🌐 forum.opencv.org
0
August 23, 2024
Python Opencv cv2.LUT() how to use - Stack Overflow
Need to apply some rapid conversion on the color channels of a image. 1)I have stored in a list the corresponding output value: ListaVred = [0]*255 for i in range(0,255): ListaVred[i]=i*127 ... More on stackoverflow.com
🌐 stackoverflow.com
[Question] Efficient LUT for 16 bit data type?
If you plan on manually setting you could use a dictionary and if the key exists modify else set to 0 More on reddit.com
🌐 r/opencv
7
1
January 27, 2025
🌐
GitHub
gist.github.com › blroot › b22abc23526af2711d92cc3b3f13b907
OpenCV python3 lut examples · GitHub
OpenCV python3 lut examples. GitHub Gist: instantly share code, notes, and snippets.
🌐
OpenCV
docs.opencv.org › 4.13.0 › db › da5 › tutorial_how_to_scan_images.html
OpenCV: How to scan images, lookup tables and time measurement with OpenCV
In image processing it's quite common that you want to modify all of a given image values to some other value. OpenCV provides a function for modifying image values, without the need to write the scanning logic of the image. We use the cv::LUT() function of the core module.
Author: opencv
🌐
LearnOpenCV
learnopencv.com › home › lut
LUT | LearnOpenCV
In this tutorial we will first show a simple way to pseudocolor / false color a grayscale image using OpenCV’s predefined colormaps.
🌐
OpenCV
forum.opencv.org › c++
Applying LUT on a cv::Mat - C++ - OpenCV
August 23, 2024 - 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 maximu…
Find elsewhere
🌐
OpenCV
docs.opencv.org › 4.13.0 › d2 › de8 › group__core__array.html
OpenCV: Operations on arrays
The function LUT fills the output array with values from the look-up table. Indices of the entries are taken from the input array.
🌐
OpenCV
docs.opencv.org › 4.13.0 › d4 › d62 › group__core__hal__interface__lut.html
OpenCV: Lookup table
Lookup table replacement Table consists of 256 elements of a size from 1 to 8 bytes having 1 channel or src_channels For 8s input type 128 is added to LUT index Destination should have the same element type and number of channels as lookup table elements
🌐
Reddit
reddit.com › r/opencv › [question] efficient lut for 16 bit data type?
r/opencv on Reddit: [Question] Efficient LUT for 16 bit data type?
January 27, 2025 -

OpenCV LUT() apparently only supports 8 bit data types, so I've put together a numpy solution, my question is if this method can be improved upon, or made more efficient?

import cv2
import numpy as np

image = np.zeros((5,5), dtype=np.uint16)
image[1][1] = 1
image[2][2] = 5

lut = np.zeros((65535), dtype=np.uint16)
lut[1] = 500
lut[5] = 1234

#new = cv2.LUT(image, lut) # LUT() is uint8 only?
new = lut[image] # NP workaround for uint16

print(image)
print(new)

...

[[0 0 0 0 0]
 [0 1 0 0 0]
 [0 0 5 0 0]
 [0 0 0 0 0]
 [0 0 0 0 0]]
[[   0    0    0    0    0]
 [   0  500    0    0    0]
 [   0    0 1234    0    0]
 [   0    0    0    0    0]
 [   0    0    0    0    0]]
🌐
OpenCV Q&A Forum
answers.opencv.org › question › 70957 › lut-must-have-1-channel-or-the-number-of-channels-of-the-input-image
LUT must have 1 channel or the number of channels of the input image?!? - OpenCV Q&A Forum
September 16, 2015 - lut – look-up table of 256 elements; in case of multi-channel input array, the table should either have a single channel (in this case the same table is used for all channels) or the same number of channels as in the input array.
🌐
LearnOpenCV
learnopencv.com › home › applycolormap for pseudocoloring in opencv ( c++ / python )
OpenCV applyColorMap: Pseudocoloring in C++ and Python
October 23, 2025 - Map the colors using a lookup table : In OpenCV you can apply a colormap stored in a 256 x 1 color image to an image using a lookup table LUT.
🌐
OpenCV
docs.opencv.org › 4.13.0 › d7 › d32 › lut_8hpp.html
OpenCV: opencv2/cudev/ptr2d/lut.hpp File Reference
Include dependency graph for lut.hpp: This graph shows which files directly or indirectly include this file: Generated on Wed Dec 31 2025 07:26:20 for OpenCV by 1.12.0
🌐
OpenCV Q&A Forum
answers.opencv.org › question › 206755 › lut-for-16bit-image
LUT for 16bit image - OpenCV Q&A Forum
Hi, I want to do lookuptable for 16 bit image. I have image of 16 bit(CV_16UC1), then i naormalize image with RGB give value and store in Mat variable called lut(type - CV_16UC3). After that, i split Mat lut and store in lut_channels. int planes = 3; vector lut_channels(planes); vector merge_elem; int glevl = 65535; int dim(glevl + 1); Mat lut(1, &dim, CV_16UC3); for (double j = 0; j (j)[0] = glevl*color*r; lut.at (j)[1] = glevl*color*g; lut.at (j)[2] = glevl*color*b; } split(lut, lut_channels); for (int k = 0; k
Top answer
1 of 1
7

As you've already discovered, the implementation of OpenCV's LUT method only supports 8-bit LUTs. However, you can implement your own for arbitrary bit resolutions and it's actually quite simple. For each value in the image, this is directly used to access the LUT which will output the desired value. Because OpenCV interfaces with NumPy, you can just use the input image and index into the LUT directly in order to obtain the final output, taking advantage of NumPy array indexing.

First define a LUT - you'll need to ensure it's 16-bit and I'm assuming you have values that go from 0 to 65535 to respect the 16-bit resolution. Once you do that, use the table to index into your image. Here's an example using gamma adjusting:

import numpy as np

def adjust_gamma(image, gamma=1.0):
    # build a lookup table mapping the pixel values [0, 65535] to
    # their adjusted gamma values
    inv_gamma = 1.0 / gamma
    table = ((np.arange(0, 65536) / 65535) ** inv_gamma) * 65535

    # Ensure table is 16-bit
    table = table.astype(np.uint16)

    # Now just index into this with the intensities to get the output
    return table[image]

This applies inverse gamma adjusting of an input image, where we first generate a LUT that is 16-bit, then the image is used to directly index into it to create the output image. Take note that the input image is also assumed to be 16-bit. If you have any values that are beyond the 0-65535 range, this will give you an out-of-bounds indexing error.

Note - Multi-channel images

Take note that the above case assumes a single-channel image. If you want to apply this for multi-channel (i.e. RGB images), then you'll need to define a LUT for each channel and apply the LUT to each channel separately. The easiest way to do this would be a for loop across all channels. There are definitely more vectorized ways to do this in one-shot, but I will not diverge from the intent of your question and I want this to be as simple to read as possible.

First define a 2D LUT where each row in this matrix is a single LUT. Specifically, row i corresponds to the LUT to apply to channel i of the image. Once you're finished, loop through the channel dimension and apply the LUT. What we can also do to save some time is to preallocate the output image so that it's all zeroes, then fill in each channel accordingly.

Something like:

# Assume LUT is defined as `table` and it's a 2D NumPy array
output = np.zeros_like(image)
for i in range(image.shape[2]):
    output[..., i] = table[i, image[..., i]]

output will contain the desired result. However, for the special case where the LUT is the same across all channels, you can just use the same 1D LUT you had previously and you can use the same indexing method that I talked about earlier:

output = table[image]
🌐
GitHub
github.com › Milchreis › OpenCV-LUT-Editor › blob › master › README.md
OpenCV-LUT-Editor/README.md at master · Milchreis/OpenCV-LUT-Editor
Tool to create freehand color correction lookup tables for OpenCV Implemented in Processing for OpenCV and experimentational research.
Author: Milchreis
🌐
GitHub
gist.github.com › Seachaos › 9da67554ef13d7397e2f98c10cd4ef27
OpenCV cpp example for lut · GitHub
OpenCV cpp example for lut. GitHub Gist: instantly share code, notes, and snippets.