当前位置:首页 > 代码 > 正文

小波阈值分割图像matlab代码(matlab绘制小波等值线图)

admin 发布:2022-12-19 22:19 149


本篇文章给大家谈谈小波阈值分割图像matlab代码,以及matlab绘制小波等值线图对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

求基于小波阈值变换及相关系数的图像降噪matlab仿真程序

供参考:

lev=5;

[c,l]=wavedec(x,lev,wname);

sigma=wnoisest(c,l,1);

alpha=2;

thr1=wbmpen(c,l,sigma,alpha)

[thr2,nkeep]=wdcbm(c,l,alpha)

xd1=wdencmp('gbl',c,l,wname,lev,thr1,'s',1);

[xd2,cxd,lxd,perf0,perfl2]=wdencmp('lvd',c,l,wname,lev,thr2,'h');

[thr,sorh,keepapp]=ddencmp('den','wv',x)

xd3=wdencmp('gbl',c,l,wname,lev,thr,'s',1);

subplot(411);plot(x);title('原始信号','fontsize',12);

subplot(412);plot(xd1);title('使用penalty阈值降噪后信号','fontsize',12);

subplot(413);plot(xd2);title('使用Birge-Massart阈值降噪后信号','fontsize',12);

subplot(414);plot(xd3);title('使用缺省阈值降噪后信号','fontsize',12);

s=[-1.58 0.42 0.46 0.78 -0.49 0.59 -1.3 -1.42 -0.16 -1.47 -1.35 0.36 -0.44 -0.14 1 -0.5 -0.2 -0.06 -0.6 0.42 -1.52 0.51 0.76 -1.5 0.16 -1.29 -0.65 -1.48 0.6 -1.65 -0.55];

[C,L]=wavedec(s,1,'db3');

ca1=wrcoef('a',C,L,'db3',1);

x1=ca1 ;

[C,L]=wavedec(s,2,'db3');

ca2=wrcoef('a',C,L,'db3',2);

x2=ca2 ;

[C,L]=wavedec(s,3,'db3');

ca3=wrcoef('a',C,L,'db3',3);

x3=ca3 ;

[C,L]=wavedec(s,4,'db3');

ca4=wrcoef('a',C,L,'db3',4);

x4=ca4 ;

cg = wrcoef('a',C,L,'sym5',1);

x5=cg;

p=1:31;

subplot(6,1,1);plot(p,s);ylabel('s');

subplot(6,1,2);plot(p,x1);ylabel('ca1');

subplot(6,1,3);plot(p,x2);ylabel('ca2');

subplot(6,1,4);plot(p,x3);ylabel('ca3');

subplot(6,1,5);plot(p,x4);ylabel('ca4')

subplot(6,1,6);plot(p,x5);ylabel('ca5') %加入的重构,是不是你要的?

另外,虚机团上产品团购,超级便宜

跪求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环境下基于小波变换的图像去噪》刘智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代码和matlab绘制小波等值线图的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/27252.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载