# matlab代做-matlab图像代做编程小波的图像压缩技术

### 时间：2018-2-6 19:29:17 点击：

function x = waverec_process(cf_vec, dim_vec, wave_name, th)

if nargin < 4
th = 10;
end
[lf, hf] = wfilters(wave_name, 'r');
dn = 3;
num = (length(cf_vec)-1)/dn;
ya = cf_vec{1};
for i = 1 : num
yv = cf_vec{(i-1)*3+2};
yh = cf_vec{(i-1)*3+3};
yd = cf_vec{(i-1)*3+4};
yv(abs(yv)<th) = 0;
yh(abs(yh)<th) = 0;
yd(abs(yd)<th) = 0;
ya = idwt2_process(ya, yv, yh, yd, lf, hf, dim_vec(i+1,:));
end
x = im2uint8(mat2gray(ya));
figure; imshow(x, []); title('重构图像');

function [cf_vec, dim_vec] = wavedec_process(x, num, wave_name)

if ndims(x) == 3
x = rgb2gray(x);
end
[lf, hf] = wfilters(wave_name, 'd');
o = x;
x = double(x);
cf_vec = [];
dim_vec = size(x);
for i = 1 : num
[ya, yv, yh, yd] = dwt2_process(x, lf, hf);
tmp = {yv; yh; yd};
dim_vec = [size(yv); dim_vec];
cf_vec=[tmp; cf_vec];
x = ya;
end
cf_vec = [ya; cf_vec];
figure; imshow(o, []); title('原图像');
plot_wave_coef(cf_vec);
plot_wave_coef_join(cf_vec, dim_vec);

function S=PSNR(s,t)
[m, n, ~]=size(s);
s = im2uint8(mat2gray(s));
t = im2uint8(mat2gray(t));
s = double(s);
t = double(t);
sd = 0;
mi = m*n*max(max(s.^2));
for u = 1:m
for v = 1:n
sd = sd+(s(u,v)-t(u,v))^2;
end
end
if sd == 0
sd = 1;
end
S = mi/sd;
S = 10*log10(S);

function plot_wave_coef_join(cf_vec,dim_vec)
dn = 3;
num = (length(cf_vec)-1)/dn;
tmpa = wkeep(cf_vec{1}, dim_vec(1, :), 'c');
tmpa = im2uint8(mat2gray(tmpa));
tmpa(1, :) = 255; tmpa(end, :) = 255;
tmpa(:, 1) = 255; tmpa(:, end) = 255;
for j = 1:num
tmpv = wkeep(cf_vec{(j-1)*dn+2}, dim_vec(j, :), 'c');
tmph = wkeep(cf_vec{(j-1)*dn+3}, dim_vec(j, :), 'c');
tmpd = wkeep(cf_vec{(j-1)*dn+4}, dim_vec(j, :), 'c');
tmpv = im2uint8(mat2gray(tmpv));
tmph = im2uint8(mat2gray(tmph));
tmpd = im2uint8(mat2gray(tmpd));
tmpv(1, :) = 255; tmpv(end, :) = 255;
tmpv(:, 1) = 255; tmpv(:, end) = 255;
tmph(1, :) = 255; tmph(end, :) = 255;
tmph(:, 1) = 255; tmph(:, end) = 255;
tmpd(1, :) = 255; tmpd(end, :) = 255;
tmpd(:, 1) = 255; tmpd(:, end) = 255;
tmp = [tmpa,tmpv;tmph,tmpd];
stc = size(tmp);
if stc >= dim_vec(j+1, :)
tmpa = tmp(1:dim_vec(j+1, 1), 1:dim_vec(j+1,2));
else
tmp = tmp([1:end-1, end-2:end-1], [1:end-1, end-2:end-1]);
tmpa = tmp(1:dim_vec(j+1, 1), 1:dim_vec(j+1,2));
end
tmpa = im2uint8(mat2gray(tmpa));
tmpa(1, :) = 255; tmpa(end, :) = 255;
tmpa(:, 1) = 255; tmpa(:, end) = 255;
end
figure;
imshow(tmpa, []);
title('小波系数塔式图');
function plot_wave_coef(cf_vec)
dn = 3;
num = (length(cf_vec)-1)/dn;
figure;
subplot(num+1, 3, 2);
yt = im2uint8(mat2gray(cf_vec{1}));
imshow(yt, []);
title(sprintf('近似分量A_{%d}', num));
info = {'垂直细节V', '水平细节H', '对角线细节D'};
ps = 2;
for i = 1 : num
for j = 1 : dn
yt = im2uint8(mat2gray(cf_vec{ps}));
subplot(num+1, dn, ps+2);
imshow(yt, []);
title(sprintf('%s_{%d}', info{j}, num-i+1));
ps = ps+1;
end
end

• 百度搜索
• 查阅资料过程中
• 论坛发现
• 百度贴吧发现
• 朋友介绍
• 没有相关文章
• 大名：
• 内容：