① 用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); % 重構圖像