㈠ 跪求MATLAB小波软硬阈值图象去噪的代码
%设置信噪比和随机种子值
snr=4;
init=2055615866;
%产生原始信号sref和高斯白噪声污染的信号s
[sref,s]=wnoise(1,11,snr,init);
%用db1小波对原始信号进行3层分解并提取系数
[c,l]=wavedec(s,3,'db1');
a3=appcoef(c,l,'db1',3);
d3=detcoef(c,l,3);
d2=detcoef(c,l,2);
d1=detcoef(c,l,1);
thr=1;
%进行硬阈值处理
ythard1=wthresh(d1,'h',thr);
ythard2=wthresh(d2,'h',thr);
ythard3=wthresh(d3,'h',thr);
c2=[a3 ythard3 ythard2 ythard1];
s3=waverec(c2,l,'db1');
%进行软阈值处理
ytsoftd1=wthresh(d1,'s',thr);
ytsoftd2=wthresh(d2,'s',thr);
ytsoftd3=wthresh(d3,'s',thr);
c3=[a3 ytsoftd3 ytsoftd2 ytsoftd1];
s4=waverec(c3,l,'db1');
%对上述信号进行图示
subplot(5,1,1);plot(sref);title('参考信号');
subplot(5,1,2);plot(s);title('染噪信号');
subplot(5,1,3);plot(s3);title('硬阈值处理');
subplot(5,1,4);plot(s4);title('软阈值处理');
㈡ 急求大神帮助 相对一幅图像进行降噪处理 求能把自适应滤波和小波软阈值降噪的matlab代码
自适应滤波
clear all
I1=imread('1.jpg');
I=rgb2gray(I1);
J=imnoise(I,'gaussian',0,0.05); %添加均值为0,方差为0.05的高斯噪声
K1=wiener2(J,[5,5]);
figure
imshow(J);
title('加入高斯噪声图像');
figure
imshow(K1);
title('5*5窗口自适应滤波');
小波软阈值
clear all
I1=imread('1.jpg');
I=rgb2gray(I1);
J=imnoise(I,'gaussian',0,0.05); %添加均值为0,方差为0.05的高斯噪声
[Cr, Sr] = wavedec2(J, 2, 'sym4');
thr= Donoho(J);
J_soft = wdenoise(xr, 'gbl', 's', thr, 'sym4', 2);
figure; imshow(J_soft);
/////////////////////////////////用到的函数
function thr = Donoho(x)
%用Donoho通用阈值公式计算阈值 x为要进行处理的图像
% thr = delta * sqrt( 2 * log(n))
% n为信号的长度或尺寸
% delta = MAD / 0.6745 -经验公式,其中MAD为小波分解后高子带系数的中值
n = prod( size(x) ); %图像尺寸
%计算delta
[C, S] = wavedec2(x, 1, 'db1'); %小波分解
d = C( prod( S(1,:) ) + 2 * prod( S(2,:) ) + 1 : end); %HH子带系数
delta = median( abs(d) ) / 0.6745;
%计算阈值
thr = delta * sqrt(2*log(n));
////////////////////////////////////用到的函数
function X = wdenoise(x, measure, sorh, thr, wname, n)
% 阈值去噪函数
% x为带噪声图像
% measure表示全局或局部
% sorh表示软硬阈值方法
% thr为阈值
% wname为小波函数名
% n为分解层次
[C, S] = wavedec2(x, n, wname); % 对图像进行小波分解
switch measure
case 'gbl' % 全局阈值方法
dcoef = C( prod(S(1, :)) + 1 : end); % 提取细节部分系数
switch sorh
case 'h' % 硬阈值
dcoef = dcoef .* (abs(dcoef) > thr);
case 's' % 软阈值
temp = abs(dcoef) - thr;
temp = (temp + abs(temp)) / 2;
dcoef = sign(dcoef) .* temp;
end
C( prod(S(1, :)) + 1 : end) = dcoef;
case 'lvd' % 局部阈值方法
for i = n:-1:1 % 每层单独处理
k = size(S,1) - i;
first = prod(S(1, :)) + ...
3 * sum(S(2:k-1, 1) .* S(2:k-1, 2)) + 1;
% 第i层细节系数的起始位置
last = first + 3*prod(S(k,:)) - 1; % 终止位置
dcoef = C(first : last); % 细节系数
switch sorh
case 'h' % 硬阈值
dcoef = dcoef .* (abs(dcoef) > thr(i));
case 's' % 软阈值
temp = abs(dcoef) - thr(i);
temp = (temp + abs(temp)) / 2;
dcoef = sign(dcoef) .* temp;
end
C(first:last) = dcoef;
end
end
X = waverec2(C, S, wname); % 重构图像
㈢ 小波阈值去噪MATLAB
不知道怎么改啊,我也在做小波去噪,是对信号进行处理,可是出来的结果不对
㈣ 用matlab实现基于边缘检测的图象小波阈值去噪方法
Press the "Start" button to see a demonstration of
denoising tools in the Wavelet Toolbox.
This demo uses Wavelet Toolbox functions.
% Set signal to noise ratio and set rand seed.
sqrt_snr = 3; init = 2055615866;
% Generate original signal and a noisy version adding
% a standard Gaussian white noise.
[xref,x] = wnoise(3,11,sqrt_snr,init);
% Denoise noisy signal using soft heuristic SURE thresholding
% and scaled noise option, on detail coefficients obtained
% from the decomposition of x, at level 5 by sym8 wavelet.
% Generate original signal and a noisy version adding
% a standard Gaussian white noise.
lev = 5;
xd = wden(x,'heursure','s','one',lev,'sym8');
% Denoise noisy signal using soft SURE thresholding.
xd = wden(x,'rigrsure','s','one',lev,'sym8');
% Denoise noisy signal using fixed form threshold with
% a single level estimation of noise standard deviation.
xd = wden(x,'sqtwolog','s','sln',lev,'sym8');
% Denoise noisy signal using fixed minimax threshold with
% a multiple level estimation of noise standard deviation.
xd = wden(x,'minimaxi','s','sln',lev,'sym8');
% If many trials are necessary, it is better to perform
% decomposition one time and threshold it many times :
% decomposition.
[c,l] = wavedec(x,lev,'sym8');
% threshold the decomposition structure [c,l].
xd = wden(c,l,'minimaxi','s','sln',lev,'sym8');
% Load electrical signal and select a part.
load leleccum; indx = 2600:3100;
x = leleccum(indx);
% Use wdencmp for signal de-noising.
% find default values (see ddencmp).
[thr,sorh,keepapp] = ddencmp('den','wv',x);
% denoise signal using global thresholding option.
xd = wdencmp('gbl',x,'db3',2,thr,sorh,keepapp);
% Some trial examples without commands counterpart.
% Rand initialization: init = 2055615866;
% Square root of signal to noise ratio: sqrt_snr = 5;
% [xref,x] = wnoise(1,11,sqrt_snr,init);
% Some trial examples without commands counterpart (more).
% Rand initialization: init = 2055615866;
% Square root of signal to noise ratio: sqrt_snr = 4;
% [xref,x] = wnoise(2,11,sqrt_snr,init);
% Some trial examples without commands counterpart (more).
% Rand initialization: init = 2055615866;
% Square root of signal to noise ratio: sqrt_snr = 3;
% [xref,x] = wnoise(3,11,sqrt_snr,init);
% Some trial examples without commands counterpart (more).
% Rand initialization: init = 2055615866;
% Square root of signal to noise ratio: sqrt_snr = 3;
% [xref,x] = wnoise(3,11,sqrt_snr,init);
% Some trial examples without commands counterpart (more).
% Rand initialization: init = 2055615866;
% Square root of signal to noise ratio: sqrt_snr = 3;
% [xref,x] = wnoise(3,11,sqrt_snr,init);
% Some trial examples without commands counterpart (more).
% Rand initialization: init = 2055615866;
% Square root of signal to noise ratio: sqrt_snr = 3;
% [xref,x] = wnoise(3,11,sqrt_snr,init);
㈤ matlab怎么用小波包进行图像去噪
小波图像来去噪的方法大概分为自3类
1:基于小波变换摸极大值原理
2:基于小波变换系数的相关性
3:基于小波阈值的去噪。
基于小波阈值的去噪方法3个步骤:
1: 计算含噪声图像的小波变换。选择合适的小波基和小波分解层数J,运用Matlab 分解算法将含有噪声图像进行J层小波分解,得到相应的小波分解系数。
2:对分解后的高频系数进行阈值量化,对于从1 到J的每一层,选择一个适当的阈值和合适的阈值函数,将分解得到的高频系数进行阈值量化,得到估计小波系数。
3:进行小波逆变化,根据图像小波分解后的第J层,低频 系数(尺度系数)和经过阈值量化处理的各层高频系数(小波系数),运用Matlab重构算法进行小波重构,得到去噪后的图像。
㈥ 急!!!在线等,求解答:一个小波去噪的matlab程序,高手进
%%%%%%%%%%%%%%%%%%心电信号降噪
%%%%%%%%%%%%%%%Birge-Massart策略阈值降噪
%基于小波变换的心电信号的降噪
ecg=fopen('100.dat','r');% 调用心电数据库 r为只读,ecg是打开文件的识别符
N=1201;%常数赋值,要读数据个数
data=fread(ecg,N,'int16'); %从一个流中读N个数据,数据格式是int16,16进制整数
data=data/10000;%数据缩小10000倍
fclose(ecg);%关闭打开的文件
x=data;%把数据转赋给x变量
wavename='db5'; %db5是小波名
level=4;%4级分解
[c,l]=wavedec(x,level,wavename); %4级小波分解,c保存各级分解系数,l是薄记矩阵,保存各级的系数的个数
alpha=1.5; %1.5用于信号压缩,3用于降噪
sorh='h'; %为硬阈值
[thr,nkeep]=wdcbm(c,l,alpha);%使用Birgé-Massart策略计算一维小波分解或压缩的阈值thr和各级的系数个数nkeep
[xc,cxc,lxc,perf0,perfl2]=wdencmp('lvd',c,l,wavename,level,thr,sorh); %小波压缩重构后的图像
t1=0:0.004:(length(x)-1)*0.004;%一行数据
figure(4);%打开一个图形窗口
subplot(211); %子图1
plot(t1,x);%画图形
title('从人体采集的原始的ECG信号');%加上子图名称
subplot(212);%子图2
plot(t1,xc);%画图形
title('Birge-Massart策略阈值降噪后的ECG信号(wname=db5 level=4)');%加上子图名称