opencv - Multi-channels LUT opencv2 python assert error -
i trying use cv2 lut image transfer in python. lut needs has same number of channels image. can't solve 1 error:
image1transfered = cv2.lut(image1, lut) cv2.error: /build/buildd/opencv-2.3.1/modules/core/src/convert.cpp:1037: error: (-215) (lutcn == cn || lutcn == 1) && lut.total() == 256 && lut.iscontinuous() && (src.depth() == cv_8u || src.depth() == cv_8s) in function lut
here python code, believe can split image multiple single channels , apply lut respectively. waste of resource.
    #!/usr/bin/python     import sys     import cv2     import numpy np      image1 = cv2.imread("../pic1.jpg", 1)     # apply table     lut = np.arange(255, -1, -1, dtype = image1.dtype )     lut = np.column_stack((lut, lut, lut))     image1converted = cv2.lut(image1, lut)  # <-- fails thank time.
you using np.column_stack() create 3-channel image, not right function. have use either np.dstack() or cv2.merge(). works fine.
eg:
in [3]: x array([[0, 1, 2],        [3, 4, 5],        [6, 7, 8]])  in [5]: np.column_stack((x,x,x)) array([[0, 1, 2, 0, 1, 2, 0, 1, 2],        [3, 4, 5, 3, 4, 5, 3, 4, 5],        [6, 7, 8, 6, 7, 8, 6, 7, 8]])  in [6]: np.dstack((x,x,x)) array([[[0, 0, 0],         [1, 1, 1],         [2, 2, 2]],         [[3, 3, 3],         [4, 4, 4],         [5, 5, 5]],         [[6, 6, 6],         [7, 7, 7],         [8, 8, 8]]])  in [11]: cv2.merge((x,x,x)) array([[[0, 0, 0],         [1, 1, 1],         [2, 2, 2]],         [[3, 3, 3],         [4, 4, 4],         [5, 5, 5]],         [[6, 6, 6],         [7, 7, 7],         [8, 8, 8]]], dtype=int32) 
Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
ReplyDeleteBig Data Hadoop Training In Chennai | Big Data Hadoop Training In anna nagar | Big Data Hadoop Training In omr | Big Data Hadoop Training In porur | Big Data Hadoop Training In tambaram | Big Data Hadoop Training In velachery
Thanks for sharing the wonderful post!
ReplyDeleteDigital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery