如何将pyWavelet和openCV结合起来进行图像处理?
作者:互联网
我需要在python中进行图像处理.我想使用小波变换作为滤波器组.任何人都可以建议我应该使用哪个库?
我安装了pywavelet,但我不知道如何将它与opencv结合起来.如果我使用wavedec2命令,它会引发ValueError(“预期的2D输入数据.”)
谁能帮我?
解决方法:
希望这可以帮助
import numpy as np
import pywt
import cv2
def w2d(img, mode='haar', level=1):
imArray = cv2.imread(img)
#Datatype conversions
#convert to grayscale
imArray = cv2.cvtColor( imArray,cv2.COLOR_RGB2GRAY )
#convert to float
imArray = np.float32(imArray)
imArray /= 255;
# compute coefficients
coeffs=pywt.wavedec2(imArray, mode, level=level)
#Process Coefficients
coeffs_H=list(coeffs)
coeffs_H[0] *= 0;
# reconstruction
imArray_H=pywt.waverec2(coeffs_H, mode);
imArray_H *= 255;
imArray_H = np.uint8(imArray_H)
#Display result
cv2.imshow('image',imArray_H)
cv2.waitKey(0)
cv2.destroyAllWindows()
w2d("test1.png",'db1',10)
标签:python,image-processing,opencv,dwt 来源: https://codeday.me/bug/20190714/1459518.html