① 用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
不知道怎么改啊,我也在做小波去噪,是对信号进行处理,可是出来的结果不对
③ 小波去噪matlab程序
哈哈!傻眼了吧,理论和实际不可兼得啊!对于你这个问题有如下建议:
小波去噪的试验,十个有九个都喜欢用正、余弦函数,但由于小波函数的几何特征,其实不易得到满意效果,你只能选择线性强的小波基,即对称性强并且光滑的小波,嘿嘿,貌似能做DWT的所有小波基中只有sym8的对称性最强(参看http://..com/question/585223273699457565.html?from=pubpage&msgtype=2),这样你将会得到其降噪效果好于其它小波基的谬论,实际应用中如果原始信号本身特征就不规律对称则有可能其它小波基的处理效果会好于sym8,这需要试错的方法试验,是你这个原始信号对称的前提假设造成的,但不可认为sym8适合你这个特殊例子就得出结论,你这试验只适合你的假设,其实并不适合所有情形,个人认为其实不具说服力和可比性。如同我家钥匙开不了你家门,是不能得出我家钥匙不如你家钥匙的结论滴。
当你的噪声特征与信号的特征的频率相近时,小波也无能为力,它不是神,也一样分不出啥是噪声,所以其一是可增加分解层数,你这个信号只有100个数,5层已经很高了,再增大也没啥用了,可能会过多显示小波基的特征,造成扭曲失真(如果用SWT会好很多,但需要自己编制函数);其二是参数SCAL可以改为伸缩的sln,而不是固定的one,这样分解层数和SCAL都将起作用,你可以试着改改玩,效果还行。
分解8层
你可以试试只分解一层的状况,频率最低的几处噪声会保留下来哦!
④ 求几个小波去噪的Matlab代码,急!!!!!!!!!!!
s %自己定义
%画出原始信号
subplot(221);
plot(s);
title('原始信号');
ylabel('幅值A');
%用db3小波对信号进行3层分解并提取系数
[c,l]=wavedec(s,3,'db3');
a3=appcoef(c,l,'db3',3);
d3=detcoef(c,l,3);
d2=detcoef(c,l,2);
d1=detcoef(c,l,1);
%强制消噪处理
dd3=zeros(1,length(d3));
dd2=zeros(1,length(d2));
dd1=zeros(1,length(d1));
c1=[a3 dd3 dd2 dd1];
s1=waverec(c1,l,'db3');
subplot(222);
plot(s1);
title('强制消噪信号');
%默认阈值进行消噪
%用ddencmp函数获得信号的默认阈值
[thr,sorh,keepapp]=ddencmp('den','wv',s);
s2=wdencmp('gbl',c,l,'db3',3,thr,sorh,keepapp);
subplot(223);
plot(s2);
title('默认阈值消噪');
xlabel('样本序号n');
ylabel('幅值A');
%用给定的软阈值进行消噪
softd1=wthresh(d1,'s',1.465);
softd2=wthresh(d2,'s',1.823);
softd3=wthresh(d3,'s',2.768);
c2=[a3 softd3 softd2 softd1];
s3=waverec(c2,l,'db3');
subplot(224);
plot(s3);
title('给定软阈值消噪');
⑤ 急!!!在线等,求解答:一个小波去噪的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)');%加上子图名称
⑥ 求小波变换图像降噪的matlab代码
%源代码来自于在《MATLAB环境下基于小波变换的图像去噪》刘智clear;clc % 清理工作空间
load wbarb; % 装载原始图像
subplot(221); % 新建窗口
image(X); % 显示图像
colormap(map); % 设置色彩索引图
title('原始图像'); % 设置图像标题
axis square; % 设置显示比例,生成含噪图像并图示
init=2055615866; % 初始值
randn('seed',init); % 随机值
XX=X+8*randn(size(X)); % 添加随机噪声
subplot(222); % 新建窗口
image(XX); % 显示图像
colormap(map); % 设置色彩索引图
title('含噪图像'); % 设置图像标题
axis square; %用小波函数coif2 对图像XX 进行2 层分解
[c,l]=wavedec2(XX,2,'coif2'); % 分解
n=[1,2]; % 设置尺度向量
p=[10.28,24.08]; % 设置阈值向量,对高频小波系数进行阈值处理
%nc=wthcoef2('h',c,l,n,p,'s');
%nc=wthcoef2('v',c,l,n,p,'s');
nc=wthcoef2('d',c,l,n,p,'s');
X1=waverec2(nc,l,'coif2'); % 图像的二维小波重构
subplot(223); % 新建窗口
image(X1); % 显示图像
colormap(map); %设置色彩索引图
title('第一次消噪后的图像'); % 设置图像标题
axis square; % 设置显示比例,再次对高频小波系数进行阈值处理
%mc=wthcoef2('h',nc,l,n,p,'s');mc=wthcoef2('v',nc,l,n,p,'s');
mc=wthcoef2('d',nc,l,n,p,'s');
X2=waverec2(mc,l,'coif2'); % 图像的二维小波重构
subplot(224); % 新建窗口
image(X2); % 显示图像
colormap(map); % 设置色彩索引图
title('第二次消噪后的图像'); % 设置图像标题
axis square; % 设置显示比例
⑦ 跪求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); % 重构图像