
一、小波入门简介
(1)小波分析的起源、发展与应用
>
自适应滤波
clear all
I1=imread('1jpg');
I=rgb2gray(I1);
J=imnoise(I,'gaussian',0,005); %添加均值为0,方差为005的高斯噪声
K1=wiener2(J,[5,5]);
figure
imshow(J);
title('加入高斯噪声图像');
figure
imshow(K1);
title('55窗口自适应滤波');
小波软阈值
clear all
I1=imread('1jpg');
I=rgb2gray(I1);
J=imnoise(I,'gaussian',0,005); %添加均值为0,方差为005的高斯噪声
[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 / 06745 -经验公式,其中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) ) / 06745;
%计算阈值
thr = delta sqrt(2log(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 + 3prod(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); % 重构图像
方法一:filter2
clear all;
I=imread('lenabmp');
%读入预处理图像
imshow(I)
%显示预处理图像
K1=filter2(fspecial('average',3),I)/255;
%进行33均值滤波
K2=filter2(fspecial('average',5),I)/255;
%进行55均值滤波
K3=filter2(fspecial('average',7),I)/255;
%进行77均值滤波
figure,imshow(K1)
figure,imshow(K2)
figure,imshow(K3)
方法二:双循环语句,移动平均法
%均值滤波
clc,clear;
f=imread('lenabmp');
subplot(121),imshow(f),title('原图');
f1=imnoise(f,'gaussian',0002,00008);
%subplot(222),imshow(f1),title('添加高斯噪声图');
k1=floor(3/2)+1;
k2=floor(3/2)+1;
X=f1;
[M,N]=size(X);
uint8 Y=zeros(M,N);
funBox=zeros(3,3);
for i=1:M-3
for j=1:N-3
funBox=X(i:i+3,j:j+3);
s=sum(funBox(:));
h=s/9;
Y(i+k1,j+k2)=h;
end;
end;
Y=Y/255;
subplot(122),imshow(Y),title('均值滤波');
实现图:
以上就是关于关于图像去噪,帮忙啊!全部的内容,包括:关于图像去噪,帮忙啊!、求MATLAB代码图像去噪的、急求大神帮助 相对一幅图像进行降噪处理 求能把自适应滤波和小波软阈值降噪的matlab代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)