Reputation: 30384
I am trying to take dct of an image. At first I was getting error
The function/feature is not implemented (Odd-size DCT's are not implemented) in dct
So I pad the image with zeros to make it even sized
But now I get error:
Assertion failed (type == CV_32FC1 || type == CV_64FC1) in dct
How can I solve this? Below is what I'm doing in python
img = cv2.imread(filepath)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret,thresholded = cv2.threshold(gray,200,255,cv2.THRESH_BINARY)
img = cv2.cvtColor(thresholded, cv2.COLOR_GRAY2BGR)
gray = thresholded
gray = gray.astype('float32')
#padding
BLUE = [255,0,0]
rows,cols = gray.shape
nrows = cv2.getOptimalDFTSize(rows)
ncols = cv2.getOptimalDFTSize(cols)
right = ncols - cols
bottom = nrows - rows
bordertype = cv2.BORDER_CONSTANT
gray = cv2.copyMakeBorder(img,0,bottom,0,right,bordertype, value = 0)
gray = gray.astype('float32')
dct=cv2.dct(gray)
Upvotes: 3
Views: 7526
Reputation: 1516
import cv2
import numpy as np
img = cv2.imread('imgColor.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret,thresholded = cv2.threshold(gray,200,255,cv2.THRESH_BINARY)
img = cv2.cvtColor(thresholded, cv2.COLOR_GRAY2BGR)
gray = thresholded
gray = np.float32(gray)/255.0
dct=cv2.dct(gray)
#padding
# BLUE = [255,0,0]
# rows,cols = gray.shape
# nrows = cv2.getOptimalDFTSize(rows)
# ncols = cv2.getOptimalDFTSize(cols)
# right = ncols - cols
# bottom = nrows - rows
# bordertype = cv2.BORDER_CONSTANT
# gray = cv2.copyMakeBorder(img,0,bottom,0,right,bordertype, value = 0)
# gray = np.float32(gray)/255.0
# dct=cv2.dct(gray)
This worked for me ! Found this here
Upvotes: 2