|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
简单实现了一下提升小波变换。包括Haar,(1,1),5/3,9/7 提升结构。
欢迎有兴趣的同学一起讨论
- function [res]=lifting_transform_forward(im,levels,wavetype)
- wavelet = wavetype;
- for k =1:levels
- [L,H]=Nonlinear_lifting_forward(im,wavelet);
- [LL,LH{k}] = Nonlinear_lifting_forward(L',wavelet);
- [HL{k},HH{k}] = Nonlinear_lifting_forward(H',wavelet);
- im = LL';
- end
- for k= levels:-1:1
- temp1 =cat(2,LL,LH{k});
- temp2 =cat(2,HL{k},HH{k});
- lifting_im = cat(1,temp1,temp2);
- LL = lifting_im;
- end
- res = lifting_im';
复制代码
- function [res]=lifting_transform_inverse(im,levels,wavetype)
- wavelet = wavetype;
- [m,n] = size(im);
- min_len = m/2^levels;
- LL = im([1:min_len],[1:min_len]);
- for k= levels:-1:1
- im_len = m/2^k;
- LH{k} = im([1:im_len],[im_len+1:im_len*2]);
- HL{k} = im([im_len+1:im_len*2],[1:im_len]);
- HH{k} = im([im_len+1:im_len*2],[im_len+1:im_len*2]);
- end
- for k =levels:-1:1
- up = Nonlinear_lifting_inverse(LL,LH{k},wavelet);
- down = Nonlinear_lifting_inverse(HL{k},HH{k},wavelet);
- im = Nonlinear_lifting_inverse(up',down',wavelet);
- LL= im';
- end
- res = im';
复制代码
- function [c,d]=Nonlinear_lifting_forward(im,wavelet)
- [width,height] = size(im);
- %%%%split
- for i=1:2:(width-1)
- Xo((i+1)/2,:) = im(i,:);
- end
- for i=2:2:width
- Xe(i/2,:) = im(i,:);
- end
- [sub_im_height,sub_im_width]=size(Xe);
- %%%% 5/3 lifting %%%%%%%%%%%%%%
- if isequal(wavelet, '5.3')
- next_Xe([1:sub_im_height-1],:) = Xe([2:sub_im_height],:);
- next_Xe(sub_im_height,:) = Xe(sub_im_height,:);
- d(:,:) = Xo(:,:) - (0.5*Xe(:,:)+0.5*next_Xe(:,:));
- up_d([2:sub_im_height],:) = d([1:sub_im_height-1],:);
- up_d(1,:) = d(1,:);
- c(:,:) = Xe(:,:) +(0.25*(up_d(:,:)+d(:,:)));
- end
- %%%% 9/7 lifting %%%%%%%%%%%%%%
- if isequal(wavelet, '9.7')
- alfa = -1.586134342;
- beta = -0.052980118;
- gamma = 0.882911075;
- delta = 0.443506852;
- k = 1.149604398;
- C0 = Xe;
- D0 = Xo;
- C0_1([1:sub_im_height-1],:) = C0([2:sub_im_height],:);
- C0_1(sub_im_height,:) = C0(sub_im_height,:);
- D1(:,:) = D0(:,:)+alfa.*(C0(:,:)+C0_1(:,:));
- D1_1([2:sub_im_height],:) = D1([1:sub_im_height-1],:);
- D1_1(1,:) = D1(1,:);
- C1(:,:) = C0(:,:)+beta.*(D1(:,:)+D1_1(:,:));
- C1_1([1:sub_im_height-1],:) = C1([2:sub_im_height],:);
- C1_1(sub_im_height,:) = C1(sub_im_height,:);
- D2(:,:) = D1(:,:)+gamma.*(C1(:,:)+C1_1(:,:));
- D2_1([2:sub_im_height],:) = D2([1:sub_im_height-1],:);
- D2_1(1,:) = D2(1,:);
- C2(:,:) = C1(:,:)+delta.*(D2(:,:)+D2_1(:,:));
- c = k.* C2;
- d = D2./k;
- end
- if isequal(wavelet, '1.1')
- c(:,:) = 0.5*(Xe(:,:)+Xo(:,:));
- d(:,:) = Xo(:,:)-c(:,:);
- end
- if isequal(wavelet,'Haar')
- c0 = Xe;
- d0 = Xo;
- d(:,:) = d0(:,:)-c0(:,:);
- c(:,:) = c0(:,:)+0.5.*d(:,:);
- end
- % figure;
- % imshow(uint8(c));
- % figure;
- % imshow(uint8(d));
- %
复制代码
- function [res]=Nonlinear_lifting_inverse(L,H,wavelet)
- c = L;
- d = H;
- [sub_im_height,sub_im_width]=size(L);
- %%%% 5/3 lifting %%%%%%%%%%%%%%
- if isequal(wavelet, '5.3')
- up_d([2:sub_im_height],:) = d([1:sub_im_height-1],:);
- up_d(1,:) = d(1,:);
- Xe(:,:) = c(:,:) - (0.25*(up_d(:,:)+d(:,:)));
-
- next_Xe([1:sub_im_height-1],:) = Xe([2:sub_im_height],:);
- next_Xe(sub_im_height,:) = Xe(sub_im_height,:);
- Xo(:,:) = d(:,:) + (0.5*Xe(:,:)+0.5*next_Xe(:,:));
- end
- %%%% 9/7 lifting %%%%%%%%%%%%%%
- if isequal(wavelet, '9.7')
- alfa = -1.586134342;
- beta = -0.052980118;
- gamma = 0.882911075;
- delta = 0.443506852;
- k = 1.149604398;
- D2 = d.*k;
- C2 = c./k;
- D2_1([2:sub_im_height],:) = D2([1:sub_im_height-1],:);
- D2_1(1,:) = D2(1,:);
- C1(:,:) = C2(:,:)-delta.*(D2(:,:)+D2_1(:,:));
- C1_1([1:sub_im_height-1],:) = C1([2:sub_im_height],:);
- C1_1(sub_im_height,:) = C1(sub_im_height,:);
- D1(:,:) = D2(:,:)-gamma.*(C1(:,:)+C1_1(:,:));
- D1_1([2:sub_im_height],:) = D1([1:sub_im_height-1],:);
- D1_1(1,:) = D1(1,:);
- C0(:,:) = C1(:,:)-beta.*(D1(:,:)+D1_1(:,:));
- C0_1([1:sub_im_height-1],:) = C0([2:sub_im_height],:);
- C0_1(sub_im_height,:) = C0(sub_im_height,:);
- D0(:,:) = D1(:,:)-alfa.*(C0(:,:)+C0_1(:,:));
- Xe = C0;
- Xo = D0;
- end
- if isequal(wavelet, '1.1')
- d0(:,:) = d(:,:)+c(:,:);
- c0(:,:) = 2.*(c(:,:)-0.5.*d0(:,:));
- Xe = c0;
- Xo = d0;
- end
- if isequal(wavelet,'Haar')
- c0(:,:) = c(:,:)-0.5.*d(:,:);
- d0(:,:) = d(:,:)+c0(:,:);
- Xe = c0;
- Xo = d0;
- end
- res([1:2:sub_im_height*2-1],:) = Xo(:,:);
- res([2:2:sub_im_height*2],:) = Xe(:,:);
复制代码
- function testing_lifting_linjie
- close all;
- clear all;
- clc;
- im = double(imread('lena.bmp'));
- figure;
- subplot(221);
- imshow(uint8(im));
- title('Original Image');
- levels =3;
- [im_h,im_w] = size(im);
- lifting_im = lifting_transform_forward(im,levels,'5.3');
- subplot(222);
- imshow(uint8(lifting_im));
- title('lifting coefficients');
- result_im = lifting_transform_inverse(lifting_im,levels,'5.3');
- high = sum(sum(abs(lifting_im(:,:))))
- MSE=sum(sum((result_im-im).^2))/(im_h*im_w);
- PSNR = 20*log((255*255)/MSE);
- disp([' PSNR = ',num2str(PSNR)]);
- subplot(223);
- imshow(uint8(result_im));
- title('reconstruction image')
复制代码 |
评分
-
1
查看全部评分
-
|