How to get dct of an image in python using opencv
I've been trying to figure out a way of getting a DCT of image. After getting the image and doing a bunch of filtering, I want to calculate DCT. Following is the code sniplet:
imgcv1 = cv2.split(imgcv)[0]
cv2.boxFilter(imgcv1, 0, (7,7), imgcv1, (-1,-1), False, cv2.BORDER_DEFAULT)
#resize image to 32x32
cv2.resize( imgcv1, (32, 32 ) ,imgcv1)
I've been trying to play around with the description given here but no success. When I tried something like:
dst = cv2.dct(imgcv1)
I get an error like:
cv2.error: /build/buildd/opencv-2.3.1/modules/core/src/dxt.cpp:2247: error: (-215) type == CV_32FC1 || type == CV_64FC1 in function dct
How can I get the dct? I would be grateful for your help.
you need a 1 channel image ( well, your split did that already ) float img for dct.
having a hard time to translate the c++ convertTo() method to python, so not an answer yet ;)
the c++ call would look like:
mat.convertTo( target,CV_32F, 1.0/255.0 );
// note that dct needs float values in the [0..1] range, what you've got currently is unsigned char data in the [0..255] rangeThanks for your comment. You're right. Actually I've been trying to look around for the same thing. Have a look at this post: http://stackoverflow.com/questions/7931382/calculate-discrete-cosine-transformation-of-image-with-opencv . Please let me know if you get this working. I'll post the solution if I am able to get it running .