Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, http://docs.opencv.org/trunk/modules/core/doc/operations_on_arrays.html#cv2.LUT

cv2.LUT(ListaVred,red)
TypeError: src is not a numpy array, neither a scalar


ListaVred = np.array(ListaVred)
cv2.LUT(ListaVred,red)
cv2.error: /build/opencv-Ai8DTy/opencv-2.4.6.1+dfsg/modules/core/src/convert.cpp:1195: error: (-215) (lutcn == cn || lutcn == 1) && lut.total() == 256 && lut.isContinuous() && (src.depth() == CV_8U || src.depth() == CV_8S) in function LUT
like image 576
user2239318 Avatar asked Oct 20 '25 04:10

user2239318


1 Answers

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)
like image 86
Michael Burdinov Avatar answered Oct 22 '25 04:10

Michael Burdinov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!