📄 fritdemo.m
字号:
% This Matlab script file contain examples on how to use the FRIT toolbox
% Load the test image (of size 257 by 257)
load testim
% Wavelet parameters
wname = 'db4';
nlevels = 5;
dwtmode('per');
% FRAT and FRIT
ra = frat(im);
[ri, l, m] = frit(im, nlevels, wname);
% Reconstructed image from FRIT
imrec = ifrit(ri, l, m, wname);
% First figure
figure(1)
subplot(2,2,1),
imagesc(im, [0, 1]),
title('Input image'), axis square, colorbar
subplot(2,2,2),
crange = mean(ra(:)) + std(ra(:)) * [-2, 2];
imagesc(ra, crange),
title('FRAT'), axis square, colorbar
subplot(2,2,3),
crange = mean(ri(:)) + std(ri(:)) * [-2, 2];
imagesc(ri, crange),
title('FRIT'), axis square, colorbar
subplot(2,2,4),
imagesc(imrec, [0, 1]);
title(sprintf('Reconstructed image from FRIT\n(SNR = %.2f dB)', ...
SNR(im, imrec)));
axis square, colorbar
% Now compare the compression performance
ratio = 0.999; % 99.9% compression
% Compression using FRITO
[r, l, m] = frito(im, wname);
rc = compress(r, ratio);
rim = ifrito(rc, l, m, wname);
% Compression using WAVEDEC2
im1 = im(1:end-1,1:end-1); % dyadic size
[w, wl] = wavedec2(im1, nlevels, wname);
wc = compress(w, ratio);
wim = waverec2(wc, wl, wname);
% Second figure
figure(2)
subplot(1,2,1), imagesc(wim, [0, 1]), axis square,
title(sprintf('Compressed image using WAVE2\n(Ratio = %.1f %%; SNR = %.2f dB)', ...
100*ratio, SNR(im1, wim)));
subplot(1,2,2), imagesc(rim, [0, 1]), axis square,
title(sprintf('Compressed image using FRITO\n(Ratio = %.1f %%; SNR = %.2f dB)', ...
100*ratio, SNR(im, rim)));
% Finally, the denoising problem
% Signal to noise ratio
rho = 5;
% Generate noisy image
init=2055615866; randn('seed', init);
sig = std(im(:));
imnoisy = im + (sig/rho) * randn(size(im));
imnoisy1 = imnoisy(1:end-1,1:end-1); % dyadic size
% Find the default thresholding values
[thr, sorh, keepapp] = ddencmp('den', 'wv', imnoisy1);
% Wavelet denoising
wdnim = wdencmp('gbl', imnoisy1, wname, nlevels, thr, sorh, keepapp);
% FRITO denoising
[r, l, m] = frito(imnoisy, wname);
rdn = wthresh(r, sorh, thr);
rdnim = ifrito(rdn, l, m, wname);
% Third figure
figure(3)
subplot(2,2,1),
imagesc(im, [0, 1]), axis square
title('Original image')
subplot(2,2,2),
imagesc(imnoisy, [0, 1]), axis square
title(sprintf('Noisy image\n(SNR = %.2f dB)', ...
SNR(im, imnoisy)));
subplot(2,2,3), imagesc(wdnim, [0, 1]), axis square,
title(sprintf('Denoised image using WAVE2\n(SNR = %.2f dB)', ...
SNR(im1, wdnim)));
subplot(2,2,4), imagesc(rdnim, [0, 1]), axis square,
title(sprintf('Denoised image using FRITO\n(SNR = %.2f dB)', ...
SNR(im, rdnim)));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -