www.gusucode.com > wavelet 源码程序 matlab案例代码 > wavelet/TwoDCycleSpinningExample.m
%% 2-D Cycle Spinning % This example shows how to denoise an image using cycle spinning with $8^{2}$ % = 64 shifts. %% % Load the sine image and add zero-mean white Gaussian noise with a variance % of 5. load sinsin; rng default; Xnoisy = X+sqrt(5)*randn(size(X)); subplot(211) imagesc(X); colormap(jet); title('Original Image'); subplot(212) imagesc(Xnoisy); title('Noisy Image'); %% % Determine the universal threshold from the level-1 detail coefficients. % Use the B-spline biorthogonal wavelet with 3 vanishing moments in the % reconstruction wavelet and 5 vanishing moments in the decomposition wavelet. wname = 'bior3.5'; [C,S] = wavedec2(Xnoisy,1,wname); Cdet = C(4097:end); THR = thselect(Cdet,'sqtwolog'); %% % Create a grid of 8 shifts in both the X and Y directions. This results % in a total of 64 shifts. N = 8; [deltaX, deltaY] = ndgrid(0:N-1,0:N-1); %% % Allocate a matrix of zeros the size of the image for the cycle spinning % result. Specify soft thresholding and set the level to 3. Xspin = zeros(size(X)); sorh = 's'; level = 3; %% % Use cycle spinning denoising and display the result. for nn =1:N^2 Xshift = circshift(Xnoisy, [deltaX(nn) deltaY(nn)]); [coefs,sizes] = wavedec2(Xshift,level,wname); [XDEN,cfsDEN,dimCFS] = wdencmp('gbl',coefs,sizes, ... wname,level,THR,sorh,1); XDEN = circshift(XDEN, -[deltaX(nn) deltaY(nn)]); Xspin = Xspin*(nn-1)/nn+XDEN/nn; end subplot(211) imagesc(X); colormap(jet); title('Original Image'); subplot(212) imagesc(Xspin); title('Cycle Spinning'); %% % Denoise the image using the identical parameters with the nonredundant % DWT. Compare the peak signal-to-noise (PSNR), mean square error, and energy % ratios obtained with cycle spinning and the nonredundant DWT. [coefs,sizes] = wavedec2(Xnoisy,level,wname); [XDEN,cfsDEN,dimCFS] = wdencmp('gbl',coefs,sizes,wname,3,THR,'s',1); [PSNRcs,MSEcs,~,L2RATcs] = measerr(X,Xspin) [PSNR,MSE,~,L2RAT] = measerr(X,XDEN) %% % The error measures show that cycle spinning has improved the image approximation. % The PSNR, mean square error, and energy ratio are all better in the image % denoised with cycle spinning.