逆双正交2.2小波逆DWT实现

问题描述

我有一些图像数据-应该是使用MATLAB的5/3 Le gall整数提升小波变换进行变换的。进行逆DWT的实际Matlab代码调用以下函数

liftwave('rbio2.2')

将4个128x128矩阵(LL,HL,LH,HH)和小波(从提升方案称为LS)作为输入,并返回252x252像素的图像。我不知道在进行逆DWT之前是否会添加任何填充,或者这种类型的小波生成的图像大小是否正常。

我正在寻找Matlab外部特定小波逆DWT的实现。我尝试了pywavelets,但生成的图像不同(错误)。

有人可以建议开源实现吗?

更新

我发现了following implementation of the bior2.2小波(其中有很多)具有整数到整数的映射:

void dwt_cdf53_i_ex_stride_i(
    const int *src_l,const int *src_h,int *dst,int *tmp,int N,int stride)
{
    assert( N >= 0 && NULL != src_l && NULL != src_h && NULL != dst && NULL != tmp && 0 != stride );

    // fix for small N
    if(N < 2)
        return;

    // copy src into tmp
    dwt_util_memcpy_stride_i(tmp+0,2*sizeof(int),src_l,stride,ceil_div2(N));
    dwt_util_memcpy_stride_i(tmp+1,src_h,floor_div2(N));

    // backward update 1 + backward predict 1
    for(int i=2; i<N-(N&1); i+=2)
        tmp[i] -= ( (tmp[i-1] + tmp[i+1]) + 2 ) >> 2;

    tmp[0] -= (tmp[1] + 1) >> 1;

    if(is_odd(N))
        tmp[N-1] -= (tmp[N-2] + 1) >> 1;
    else
        tmp[N-1] += tmp[N-2];

    for(int i=1; i<N-2+(N&1); i+=2)
        tmp[i] += ( tmp[i-1] + tmp[i+1] ) >> 1;

    // copy tmp into dst
    dwt_util_memcpy_stride_i(dst,tmp,sizeof(int),N);
}

如何更改它以执行反向双正交小波?

解决方法

使用反向双正交样条小波(rbio2.2)进行的逆变换与使用双正交小波(bior2.2)进行的正向变换相同。从我的头开始,带有反向小波的整数到整数逆变换的代码应如下所示:

void dwt_rcdf53_i_ex_stride_i(
    const int *src_l,const int *src_h,int *dst,int *tmp,int N,int stride)
{
    assert( N >= 0 && NULL != src_l && NULL != src_h && NULL != dst && NULL != tmp && 0 != stride );

    // fix for small N
    if(N < 2)
        return;

    // copy src into tmp
    dwt_util_memcpy_stride_i(tmp+0,2*sizeof(int),src_l,stride,ceil_div2(N));
    dwt_util_memcpy_stride_i(tmp+1,src_h,floor_div2(N));

    // predict 1 + update 1
    for(int i=1; i<N-2+(N&1); i+=2)
        tmp[i] -= (tmp[i-1] + tmp[i+1]) >> 1;

    if(is_odd(N))
        tmp[N-1] += (tmp[N-2] + 1) >> 1;
    else
        tmp[N-1] -= tmp[N-2];

    tmp[0] += (tmp[1] + 1) >> 1;

    for(int i=2; i<N-(N&1); i+=2)
        tmp[i] += ((tmp[i-1] + tmp[i+1]) + 2) >> 2;

    // copy tmp into dst
    dwt_util_memcpy_stride_i(dst,tmp,sizeof(int),N);
}