㈠ 跪求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)');%加上子圖名稱