博客
关于我
【图像去噪】基于全变分算法图像去噪matlab源码
阅读量:243 次
发布时间:2019-03-01

本文共 2662 字,大约阅读时间需要 8 分钟。

一、简介

1 用途

图像降噪(图像修复,复原中),TVloss是一种较为有效的正则项,来保持图像的光滑性。
2 效果

在这里插入图片描述

在这里插入图片描述

二、源代码

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%I=imread('toys.bmp'); % load imageI=double(I(20:120,10:105)); % cut a piece, convert to double%%% Parametersstd_n=10; var_n=std_n^2;  % Gaussian noise standard deviationreduced_pw = 1.5*var_n;   % power to reduce in first phasesig_w = 5; ws=4*sig_w+1;  % window size%%%%%%%%%%%%%%%%% Add noiseIn = randn(size(I))*std_n;I0 = I + In;  % noisy input image% show original and noisy imagesfigure(1); imshow(uint8(I)); title('Original')figure(2); imshow(uint8(I0)); title('Noisy image')snr_noisy=db(I,I0)% run normal tv - strong denoisingtic;J=I0; ep_J=0.1; % minimum mean change in image JJ_old=0;lam=0; iter=10; dt=0.2; ep=1; while (mean(mean(abs(J - J_old))) > ep_J),  % iterate until convergence   J_old=J;   J=tv(J,iter,dt,ep,lam,I0); % scalar lam   lam = calc_lam(J,I0,reduced_pw); % update lambda (fidelity term)end % while% figure(3); imshow(uint8(J)); title('residue TV')% snr_residue= db(I,J)Ir=I0-J;  % Ir scalarPr = mean(mean(Ir.^2)); % power of residueLV = loc_var(Ir,ws,sig_w^2);  % local variance (local  power of the residue )% P=mean(mean(LV));Pxy=1*(var_n^2)./LV;  %%  Sxy    inverse proportional to the LV%%% Varying Lambdalamxy=zeros(size(I0));J=I0; J_old=0; ep_J=0.001;%eps=0.01;while (mean(mean(abs(J - J_old))) > ep_J),  % iterate until convergence   J_old=J;   J=tv(J,iter,dt,ep,lamxy,I0); % adaptive lam   %J=tv(J,iter,dt,ep_J,lamxy,I0);   lamxy = calc_lamxy(J,I0,Pxy,sig_w); % update lambda (fidelity term)end % whilefigure(3); imshow(uint8(J)); title('Adaptive TV')snr_adap= db(I,J)toct1=toc%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Run scalar TV denoising for comparision %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ticJ=I0; % paramsep_J = 0.01; % minimum mean change in image Jlam=0; J_old=0;i=0;while (mean(mean(abs(J - J_old))) > ep_J),  % iterate until convergence   J_old = J;   J=tv(J,iter,dt,ep,lam,I0);     % scalar lam   lam = calc_lam(J,I0,var_n,ep); % update lambda (fidelity term) end % for i% Ir=I0-J;  % Ir scalar% Pr = mean(mean(Ir.^2)); % power of residuefunction Ig=gauss(I,ks,sigma2)%private function: gauss (by Guy Gilboa):% Ig=gauss(I,ks,sigma2)% ks - kernel size (odd number)% sigma2 - variance of Gaussian[Ny,Nx]=size(I);hks=(ks-1)/2;  % half kernel sizeif (Ny
1) xL=mean(I(:,1:hks)')'; xR=mean(I(:,Nx-hks+1:Nx)')';% xL,xR :Ny x 1 else xL=I(:,1); xR=I(:,Nx); end eI=[xL*ones(1,hks) I xR*ones(1,hks)]; % Ny x Nx+2hks if (hks>1) xU=mean(eI(1:hks,:)); xD=mean(eI(Ny-hks+1:Ny,:)); % xU,xD: 1 x Nx+2hks else xU=eI(1,:); xD=eI(Ny,:); end

三、运行结果

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

四、备注

完整代码或者代写添加QQ1575304183

往期回顾>>>>>>

 

转载地址:http://jigx.baihongyu.com/

你可能感兴趣的文章
openlayer展示热力图
查看>>
mongodb中的文档的方法---sort()、limit()、skip()
查看>>
mongodb中文档的特殊更新--upsert、remove(根据条件删除数据 )
查看>>
微信小程序中的自定义组件
查看>>
uniapp中的生物认证(指纹、人脸识别)
查看>>
HTML表单跨行跨列操作
查看>>
框架结构标签 frameset
查看>>
Eclipse-更改Eclipse中SVN用户名及密码
查看>>
使用div技术写出商城首页
查看>>
Java
查看>>
Redis
查看>>
Maven-初级
查看>>
IDEA-新建Maven项目添加依赖后还是报错
查看>>
IDEA-调出Maven导航栏
查看>>
Oracle-子查询和集合运算
查看>>
Luence
查看>>
Svn
查看>>
Mybatis-PageHelper分页插件-Spring
查看>>
springboot-配置文件
查看>>
springboot-开发热部署
查看>>