如题,请高手帮帮忙!!
能有源程序嘛?
%%给一个dwt的swt应该比这个简单。
clear;
clc;
close all;
I = imread('f:\test\chinalake.bmp','bmp');
I_temp = double(I); % read the image
[height,width] = size(I_temp); % get the size of the image
% dwt decomposition
[CA1 ,CH1 ,CV1 ,CD1] = dwt2(I_temp,'bior2.2');
[CA2 ,CH2 ,CV2 ,CD2] = dwt2(CA1,'bior2.2');
[CA3 ,CH3 ,CV3 ,CD3] = dwt2(CA2,'bior2.2');
[CA4 ,CH4 ,CV4 ,CD4] = dwt2(CA3,'bior2.2');
% store the low-frequency signal in the array CA
CA{1,1} = CA1;
CA{1,2} = CA2;
CA{1,3} = CA3;
CA{1,4} = CA4;
% store the horizon component in the array CH
CH{1,1} = CH1;
CH{1,2} = CH2;
CH{1,3} = CH3;
CH{1,4} = CH4;
% store the vertical component in the array CV
CV{1,1} = CV1;
CV{1,2} = CV2;
CV{1,3} = CV3;
CV{1,4} = CV4;
% store the digonal component in the array CD
CD{1,1} = CD1;
CD{1,2} = CD2;
CD{1,3} = CD3;
CD{1,4} = CD4;
%wavelet soft-restrict to de-noise
for i = 1:4
thr = median(median(abs(CH{1,i})));
thr = thselect(CH{1,i},'sqtwolog')*thr/0.6745;
CH{1,i} = wthresh(CH{1,i},'h',thr);
end
for i = 1:4
thr = median(median(abs(CV{1,i})));
thr = thselect(CV{1,i},'sqtwolog')*thr/0.6745;
CV{1,i} = wthresh(CV{1,i},'h',thr);
end
for i =1:4
thr = median(median(CD{1,i}));
thr = thselect(CD{1,i},'sqtwolog')*thr/0.6745;
CD{1,i} = wthresh(CD{1,i},'h',thr);
end
% reconstruction the image
%A = mean(CA4);
%flag = 0;
% the first layer
[row,cow] = size(CA4);
[r,c] = size(CH{1,4});
if row > r
A4(row,:) = [];
end
if cow > c
A4(:,cow) = [];
end
A4 = idwt2(CA4,CH{1,4},CV{1,4},CD{1,4},'bior2.2');
%figure(2);
%imshow(uint8(A4));
% the second layer
[row,cow] = size(A4);
[r,c] = size(CH{1,3});
if row > r
A4(row,:) = [];
end
if cow > c
A4(:,cow) = [];
end
A3 = idwt2(A4,CH{1,3},CV{1,3},CD{1,3},'bior2.2');
%figure(3);
%imshow(uint8(A4));
% the third layer
[row,cow] = size(A3);
[r,c] = size(CH{1,2});
if row > r
A3(row,:) = [];
end
if cow > c
A3(:,cow) = [];
end
A2 = idwt2(A3,CH{1,2},CV{1,2},CD{1,2},'bior2.2');
% the fourth layer
[row,cow] = size(A2);
[r,c] = size(CH{1,1});
if row > r
A2(row,:) = [];
end
if cow > c
A2(:,cow) = [];
end
A1 = idwt2(A2,CH{1,1},CV{1,1},CD{1,1},'bior2.2');
d_min = min(min(A1));
d_max = max(max(A1));
A1 = (A1 - d_min)/(d_max - d_min);
figure;
imshow(A1);
%imshow(uint8(A1));
%figure(2);
%imshow(I);