[Solved] Python Opencv cv2.LUT() how to use

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 / 255 + 128

2)I get the color input value from 0 to 255 from the image

3)should replace in the image the input values with the output

i.e. red[45]= 0 
     ListaVred0] = 128
     red[45]= 128

I’ve looked at cv2.LUT(src,dst) function but not sure about it’s use,

TypeError: src is not a numpy array, neither a scalar

ListaVred = np.array(ListaVred)
cv2.error: /build/opencv-Ai8DTy/opencv- error: (-215) (lutcn == cn || lutcn == 1) && lut.total() == 256 && lut.isContinuous() && (src.depth() == CV_8U || src.depth() == CV_8S) in function LUT

Solution #1:

You looked into documentation of yet to be released version of OpenCV (version 3.0). I guess you are using OpenCV 2.4.8 or lower. Check this documentation. Notice the differences in usage of LUT function. At the top of the page you will see the version of OpenCV to which this documentation belong.

LUT(srcImage, lookupTable, dstImage)
Respondent: Michael Burdinov

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.