【图像去噪】基于全变分方法图像去噪【Matlab 561期】

一、简介

全变分(Total variation),也称为全变差,是图象复原中常用的一个名词。本文简要介绍全变分的概念以及在图象去噪中的应用。

1 一维信号的全变分和去噪

1.1 一维连续函数的全变分
一维连续实函数f(x)f(x)在区间[a,b]⊂R[a,b]⊂R上的全变分定义为参数曲线x→f(x),x∈[a,b]x→f(x),x∈[a,b]的弧长。其表达式为
Vba(f)=∫ba|f′(x)|dx
Vab(f)=∫ab|f′(x)|dx
说白了,所谓的“变分”就是|f(x+Δx)−f(x)||f(x+Δx)−f(x)|,对于连续函数Δx→0Δx→0。而全变分是对函数定义的区间而言的,就是将“变分”在区间上累加起来。
一维离散信号的全变分
从上面连续实函数的全变分,我们可以很容易想到它的离散形式。给出信号序列{yi},i=1,…,n{yi},i=1,…,n,它的全变分定义为
V(y)=∑i=1n|yi+1−yi|
V(y)=∑i=1n|yi+1−yi|
用一句话来概括,全变分是前后项之差的绝对值之和。

1.2 一维信号去噪

当我们得到观察信号xixi,希望xixi变得平滑,也就是对xixi去噪。一种很直观的想法就是让信号的全变分变小。全变分对应的物理意义就是输入信号的平滑度。设得到的恢复信号为yiyi,它应该满足两个条件:
yiyi与观察信号xixi的差距不大。这个差距的常用数学表达式就是
E(x,y)=12∑i(xi−yi)2
E(x,y)=12∑i(xi−yi)2
yiyi的全变分不大。
将物理约束转化为数学模型,求解yy等价于求解下面这个优化问题:

minyE(x,y)+λV(y)
minyE(x,y)+λV(y)
其中参数λλ是正常数,用于调节两个约束的作用大小。注意到E(x,y)E(x,y)和V(y)V(y)都是凸函数,这是一个无约束凸优化问题,有很多经典方法可以求解。

2 二维离散信号(图象)的全变分和去噪

图象是典型的二维离散信号,Rudin在1992年将其全变分定义为

V(y)=∑i,j|yi+1,j−yi,j|2+|yi,j+1−yi,j|2−−−−−−−−−−−−−−−−−−−−−−−√
V(y)=∑i,j|yi+1,j−yi,j|2+|yi,j+1−yi,j|2
这个函数是各项同性的,但是不可微,也并不是凸函数。非凸函数的优化求解难度、速度和稳定性都无法与凸函数相比。因此二维全变分有另一种常用定义
V(y)=∑i,j|yi+1,j−yi,j|2−−−−−−−−−−−√+|yi,j+1−yi,j|2−−−−−−−−−−−√=∑i,j|yi+1,j−yi,j|+|yi,j+1−yi,j|
V(y)=∑i,j|yi+1,j−yi,j|2+|yi,j+1−yi,j|2=∑i,j|yi+1,j−yi,j|+|yi,j+1−yi,j|
这个函数是凸函数了。

仿照一维信号的去噪,基于全变分的图象去噪可以看成求解优化问题

minyE(x,y)+λV(y)
minyE(x,y)+λV(y)
其中E(x,y)E(x,y)作为数据误差项定义为

E(x,y)=12∑i,j(xi,j−yi,j)2
E(x,y)=12∑i,j(xi,j−yi,j)2
当VV有凸函数形式时,问题变为无约束凸优化问题,从而容易求解。

二、源代码

function [img_estimated,energyi,ISNRi,energyo,ISNRo]=tvmm_debluring(img_noisy,h,lambda,varargin)
% function   [img_estimated]=tvmm_debluring(img_noisy,h,lamdba,...
%            'optional_parameter_name1',value1,'optional_parameter_name2', value2,...);
%
% Total Variation-based image deconvolution with
% a majorization-minimization approach.
%  
% Written by: Joao Oliveira, Jose Bioucas-Dias, Mario Figueiredo
% email: joao.oliveira@lx.it.pt
% SITE: www.lx.it.pt/~jpaos/tvmm
% Date: 21/11/2005
%  
%        
% ========================== INPUT PARAMETERS (required) =================
% Parameter     Values
% name          and description
% ========================================================================
% img_noisy		(double) Noisy blured image of size ny. 
% h             (double) Blur kernel.
% lambda		Regularization parameter (which is multiplied by the
%               TV penalty).
%
% ======================== OPTIONAL INPUT PARAMETERS ====================
% Parameter     Values
% name          and description
% =======================================================================
% boa_iter      (double) The number of outer loop iterations. 
%               Default: 20 
% cg_iter       (double) The max number of inner CG iterations.
%               Default: 200
% soim_iter     (double) The max number of inner SOIM iterations.
%               Default: 20
% soim_cg_iter (double) The max number of CG iterations in inner SOIM.
%               Default: 6
% cg_thrld      (double) Conjugate Gradient threshold.
%               Default: 1e-5;
% image         (double) Original image.
% displayIm     ({
    
    'yes','no'}) if 'yes' is passed  the restored imaged
%               is displayed along the CG iterations
%               Default: 'no'
% info_energyi  ({
    
    'yes','no'}) if 'yes' is passed the isnr and energy of
%               the objective function is displayed inside the inner loop.
%               Default: 'no'
% info_energyo  ({
    
    'yes','no'}) if 'yes' is passed the energy of
%               the objective function is displayed at each outter loop.
%               Default: 'no'
% info_ISNRi    ({
    
    'yes','no'}) if 'yes' is passed the isnr is displayed.
%               Default: 'no'
%               Requires: image
% info_ISNRo    ({
    
    'yes','no'}) if 'yes' is passed the isnr is displayed.
%               Default: 'no'
%               Requires: image
% x_0           (double) initial image iteration.
%               Default: Wiener filter
% method        ({
    
    'cg','soim'}) Selects the method used to solve the linear
%               system: cg=conjugate gradient; soim=second order iterative
%               method.
%               Default: 'cg'
% l_min         (double) Minimum eigenvalue of the system for the second
%               order iterative method.
%               Default: 1e-5
% l_max         (double) Maximum eigenvalue of the system for the second
%               order iterative method.
%               Default: 1
% 
%       ===================================================================
%       The following functions can be provided in order to overwrite the 
%       internal ones. Recall that, by default, all calculations are
%       performed with circular convolutions. (see Technical Report)
%       ===================================================================
%
% mult_H        (function_handle) Function handle to the function that 
%               performes H*x. This function must accept two parameters:
%                       x : image to apply the convolution kernel h
%                       h : Blur kernel
% mult_Ht       (function_handle) Function handle to the function that 
%               performes Ht*x (Ht = H transpose). This function must 
%               accept two parameters:
%                       x : image to apply the convolution kernel h
%                       h : Blur kernel
% diffh         (function_handle) Function handle to the function that 
%               computes the horizontal differences of an image x.
% diffv         (function_handle) Function handle to the function that 
%               computes the vertical differences of an image x.
% diffht         (function_handle) Function handle to the function that 
%               computes the horizontal differences (transposed) of an 
%               image x.
% diffh         (function_handle) Function handle to the function that 
%               computes the vertical differences (transposed) of an 
%               image x.
%
%
% ====================== Output parameters ===============================
% img_estimated     Estimated image
% energyi           Energy of inner loop iterations.
%                   Required input arguments: 'info_energyi' and 'image'.
% ISNRi             Improvement Signal-to-noise ratio of inner loop iterations.
%                   Required input arguments: 'info_ISNRi' and 'image'.
% energyo           Energy of outer loop iterations.
%                   Required input arguments: 'info_energyo' and 'image'.
% ISNRo             Improvement Signal-to-noise ratio of outer loop iterations.
%                   Required input arguments: 'info_ISNRo' and 'image'.
%
% ============= EXAMPLES =========================================
% Normal use:
% [img_estimated]=tvmm_debluring(img_noisy,lambda,sigma)
% 
% Display restored images along CG iterations:
% [img_estimated]=tvmm_debluring(img_noisy,lambda,sigma,...
%                       'displayIm','yes')
%
% Perform ISNR calculations of the outer loop iterations:
% [img_estimated,energyi,ISNRi,energyo,ISNRo]=tvmm_debluring(img_noisy,...
%                       lambda,sigma,'info_SNRo','yes','image',image);
%

% ======================= DEFAULT PARAMETERS ===================
global mH mHt diffh diffv diffht diffvt
boa_iter = 20;          % Number of outer loop iterations
cg_iter = 200;          % Number of inner CG iterations
soim_iter = 20;          % Number of inner SOIM iterations
soim_cg_iter = 6;        % Number of CG iterations inside SOIM
cg_thrld = 1e-5;        % CG threshold
displayIm = 0;
image=[];
info_energyi='no';
info_energyo='no';
info_ISNRi='no';
info_ISNRo='no';
info_int = 0;
info_ext = 0;
energyi=0;
ISNRi=0;
energyo=0;
ISNRo=0;
mH=@conv2c;
mHt=@conv2c;
diffh=@f_diffh;
diffv=@f_diffv;
diffht=@f_diffht;
diffvt=@f_diffvt;
method='cg';
x_0=[];
l_min=1e-5;
l_max=1;
% ====================== INPUT PARAMETERS ========================
% Test for number of required parametres
if (nargin-length(varargin)) ~= 3
     error('Wrong number of required parameters');
end

% Read the optional parameters
if (rem(length(varargin),2)==1)
    error('Optional parameters should always go by pairs');
else
    for i=1:2:(length(varargin)-1)
        % change the value of parameter
        switch varargin{
    
    i}
            case 'boa_iter'                     % Outer loop iterations
                boa_iter = varargin{
    
    i+1};
            case 'cg_iter'                      % Inner loop iterations
                cg_iter = varargin{
    
    i+1};
            case 'soim_iter'                    % Inner loop iterations
                soim_iter = varargin{
    
    i+1};
            case 'soim_cg_iter'                 % CG iterations in Inner loop
                soim_cg_iter = varargin{
    
    i+1};
            case 'displayIm'                    % display sucessive xe estimates
                if (isequal(varargin{
    
    i+1},'yes'))
                    displayIm=1;
                end
            case 'cg_thrld'                     % CG threshold
                cg_thrld = varargin{
    
    i+1};
            case 'image'                        % Original image
                image = varargin{
    
    i+1};
            case 'info_ISNRi'                   % display ISNR inside inner loop
                info_ISNRi = varargin{
    
    i+1};
            case 'info_ISNRo'                   % display ISNR on outer loop
                info_ISNRo = varargin{
    
    i+1};
            case 'info_energyi'                 % display energy inside inner loop
                info_energyi = varargin{
    
    i+1};
            case 'info_energyo'                 % display energy on outer loop
                info_energyo = varargin{
    
    i+1};
            case 'x_0'                          % Initial image iteration
                x_0 = varargin{
    
    i+1};
            case 'mult_H'                       % Function handle to perform H*x
                mH = varargin{
    
    i+1};
            case 'mult_Ht'                      % Function handle to perform Ht*x
                mHt = varargin{
    
    i+1};
            case 'diffh'                   % External function to perform 
                diffh = varargin{
    
    i+1};     % horizontal differences    
            case 'diffv'                   % External function to perform 
                diffv = varargin{
    
    i+1};     % vertical differences    
            case 'diffht'                  % External function to perform 
                diffht = varargin{
    
    i+1};    % horizontal differences (transposed)   
            case 'diffvt'                  % External function to perform 
                diffvt = varargin{
    
    i+1};    % vertical differences (transposed)  
            case 'method'                  % External function to perform 
                method = varargin{
    
    i+1};    % vertical differences (transposed)  
            case 'l_min'                   % Minimum eigenvalue 
                l_min = varargin{
    
    i+1};       
            case 'l_max'                   % Maximum eigenvalue
                l_max = varargin{
    
    i+1};     
                
            otherwise
                % Hmmm, something wrong with the parameter string
                error(['Unrecognized parameter: ''' varargin{
    
    i} '''']);
        end;
    end;
end

三、运行结果

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

四、备注

完整代码或者代写添加QQ 912100926

猜你喜欢

转载自blog.csdn.net/m0_54742769/article/details/115280059