prior_laplace_old

PURPOSE ^

PRIOR_LAPLACE calculate image prior

SYNOPSIS ^

function Reg= prior_laplace_old( inv_model );

DESCRIPTION ^

 PRIOR_LAPLACE calculate image prior
 Reg= prior_laplace( inv_model )
 Reg        => output regularization term
 inv_model  => inverse model struct
  or
 Reg= prior_laplace( fwd_model )

 This image prior is intended to be used as
  R'*R, but may be used as R for as well.

 The Laplace prior is a 2nd order high pass filter.
 On a rectangular mesh, it is a convolution with
   [-1,-1,-1;      [ 0;-1; 0
    -1, 8,-1    or  -1; 4;-1
    -1,-1,-1]        0;-1; 0]

 On a finite element mesh, we define the it as 
 -1 for each adjacent element, and 3 (in 2D) or 4 (in 3D)
 for the element itself

 previous implementation requires searching for faces in the mesh

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function Reg= prior_laplace_old( inv_model );
0002 % PRIOR_LAPLACE calculate image prior
0003 % Reg= prior_laplace( inv_model )
0004 % Reg        => output regularization term
0005 % inv_model  => inverse model struct
0006 %  or
0007 % Reg= prior_laplace( fwd_model )
0008 %
0009 % This image prior is intended to be used as
0010 %  R'*R, but may be used as R for as well.
0011 %
0012 % The Laplace prior is a 2nd order high pass filter.
0013 % On a rectangular mesh, it is a convolution with
0014 %   [-1,-1,-1;      [ 0;-1; 0
0015 %    -1, 8,-1    or  -1; 4;-1
0016 %    -1,-1,-1]        0;-1; 0]
0017 %
0018 % On a finite element mesh, we define the it as
0019 % -1 for each adjacent element, and 3 (in 2D) or 4 (in 3D)
0020 % for the element itself
0021 %
0022 % previous implementation requires searching for faces in the mesh
0023 
0024 % (C) 2005 Andy Adler. License: GPL version 2 or version 3
0025 % $Id: prior_laplace_old.m 5720 2018-03-28 11:57:45Z aadler $
0026 
0027 if ischar(inv_model) && strcmp(inv_model,'UNIT_TEST'); do_unit_test; return; end
0028 
0029 switch inv_model.type
0030   case 'inv_model'; fwd_model = inv_model.fwd_model;
0031   case 'fwd_model'; fwd_model = inv_model;
0032   otherwise; error('PRIOR_LAPLACE requires input type of inv_model or fwd_model');
0033 end
0034 
0035 Reg = eidors_cache(@build_laplace, fwd_model, 'prior_laplace');
0036 
0037 function Reg = build_laplace(fwd_model)
0038 
0039    pp= fwd_model_parameters( fwd_model );
0040    Reg = speye( pp.n_elem );
0041 
0042    Iidx= [];
0043    Jidx= [];
0044    Vidx= [];
0045    for ii=1:pp.n_elem
0046       el_adj = find_adjoin( ii, pp.ELEM );
0047       for jj=el_adj(:)'
0048          Iidx= [Iidx, ii, ii, jj, jj];
0049          Jidx= [Jidx, ii, jj, ii, jj];
0050          Vidx= [Vidx,  1, -1, -1,  1];
0051       end
0052    end
0053 
0054    Reg = sparse(Iidx,Jidx, Vidx, pp.n_elem, pp.n_elem );
0055    
0056    
0057 % find elems which are connected to elems ee
0058 function elems= find_adjoin(ee, ELEM)
0059    nn= ELEM(:,ee);
0060    [d,e]= size(ELEM);
0061    ss = false(size(ELEM));
0062    for i=1:d
0063      ss= ss | ELEM==nn(i);
0064    end
0065    elems= find(sum(ss,1)==d-1);
0066 
0067 function do_unit_test
0068 
0069    imdl = mk_common_model('a2c2',16);
0070    RtR = prior_laplace_old( imdl );
0071    subplot(221); spy(RtR);
0072    unit_test_cmp('a2c2', nnz(RtR), 240);
0073 
0074    fmdl = mk_circ_tank(2,[],4);
0075    RtR = prior_laplace_old( fmdl );
0076    subplot(222); spy(RtR);
0077    unit_test_cmp('2-4',RtR(1:4,1:8), [ ...
0078       6, -2,  0, -2, -2,  0,  0,  0; -2,  6, -2,  0,  0, -2,  0,  0;
0079       0, -2,  6, -2,  0,  0, -2,  0; -2,  0, -2,  6,  0,  0,  0, -2]);

Generated on Tue 31-Dec-2019 17:03:26 by m2html © 2005