haar dwt in python

import sys
import cv2
import numpy as np






def algdwt_haar(img):
    h,w,c = img.shape
    if c > 1:
        img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    src = img * 1.0
    if h % 2 == 1:
        src = np.vstack((src, src[h-1]))       
    if w % 2 == 1:
        src = np.hstack((src, src[:,w-1]))


    weight = 1.0 / np.sqrt(2)
    lowf = (src[:,0::2] + src[:,1::2]) * weight
    highf = (src[:,0::2] - src[:,1::2]) * weight
    buf = np.hstack((lowf, highf))


    lowf = (buf[0::2] + buf[1::2]) * weight
    highf = (buf[0::2] - buf[1::2]) * weight
    res = np.vstack((lowf, highf))


    return (res, src.shape[0] - img.shape[0], src.shape[1] - img.shape[1])




if __name__ == "__main__":
    img = cv2.imread(sys.argv[1])
    h,w,c = img.shape
    if h > 401:
        w = np.int32(w * 401.0/h)
        img = cv2.resize(img, (h,w))
    result, dh,dw = algdwt_haar(img)
    result = np.abs(result)
    mat255 = np.ones(result.shape, float) * 255;
    img = np.minimum(result,mat255)
    img = np.uint8(img)
    cv2.imshow('dwt', img)
    cv2.waitKey(-1)
            


    

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值