Search code examples
matlabimage-processingleast-squares

How to implement regularized least squares in matlab


I am trying to implement in Matlab the paper Reducing boundary artifacts in image deconvolution available here.

The problem I am running into is that I don't know how to implement in matlab the regularized least square problem described in the paper.

regularized least square problem

Can anyone give me some suggestions? Until now I found the lasso function in matlab but I am not sure this is what I need. Thank you.


Solution

  • A=double(A);
    [M,N]=size(A);
    Dm=eye(M);
    Dn=eye(N);
    Dxx=diff(Dm,2,1); % 2nd derivative
    Dyy=diff(Dn,2,1);
    LA=kron(Dxx,Dn)+kron(Dm,Dyy); %Laplacian operator
    
    I=eye(M*N);
    A1=zeros(size(A)); 
    A1(1:alpha,:)=1;  % alpha in formula (1) and (2) from paper, boundary margin
    A1(M-alpha:M,:)=1; 
    B1=zeros(size(B));     % B is A' in the formula
    B1(1:alpha,:)=1;
    B1(M:M+alpha,:)=1;   % B1 is A-A', boundary elements padded as the paper shows
    
    H=[LA;sqrt(lambda)*I(A1,:)];  % consolidate the laplacian operator in the 1st part and the norm in the 2nd part 
    y=[zeros(size(LA,1),1);B(B1)]; % convert the original problem to a matrix equation Hx=y
    X=reshape(H\y, M,N);