目录
一、理论基础
二、核心程序
三、测试结果
一、理论基础
从数学上讲, 矩阵的秩反应了矩阵的固有属性, 矩阵的低秩性是指矩阵的秩相对于矩阵的行数和列数而言很小.低秩矩阵稀疏分解模型是将已知矩阵M (M∈Rm×n) 分解为一个低秩矩阵部分L (L∈Rm×n, rank (L) ≤m, n) 和一个稀疏矩阵部分S (S∈Rm×n) , 即M=L+S.
增广拉格朗日乘子法(ALM)
迭代阈值算法(IT)
加速近端梯度算法(APG)
交替方向乘子算法(ADMM)
二、核心程序
增广拉格朗日乘子法(ALM)
clc;
clear;
close all;
warning off;
addpath 'func\'
I1=imresize(imread('1.jpg'),[256,256]);
I2=imresize(imread('2.jpg'),[256,256]);
Init = I2;
figure;
subplot(121);
imshow(Init);
title('原始图');
%original image
x = double(rgb2gray(Init));
tic;
[A_hat,E_hat,iter] = func_ALM(x,0.1,0.05,100);
toc;
subplot(122);
imshow(A_hat,[]);
title('ALM处理结果');
迭代阈值算法(IT)
clc;
clear;
close all;
warning off;
addpath 'func\'
I1=imresize(imread('1.jpg'),[256,256]);
I2=imresize(imread('2.jpg'),[256,256]);
Init = I2;
figure;
subplot(121);
imshow(Init);
tic;
title('原始图');
%迭代阈值算法
Im = rgb2gray(Init);
[x,y]= size(Im);
b = double(Im);
zd = double(max(Im));
zx = double(min(Im));
T = double((zd+zx))/2;
count= double(0);
while 1 % 迭代最佳阈值分割算法
count=count+1;
S0=0.0; n0=0.0;
S1=0.0; n1=0.0;
for i=1:x
for j=1:y
if double(Im(i,j))>=T
%大于阈域值图像点灰度值累加
S1=S1+double(Im(i,j));
%大于阈域值图像点个数累加
n1=n1+1;
else
%小于阈域值图像点灰度值累加
S0=S0+double(Im(i,j));
%小于阀域值图像点个数累加
n0=n0+1;
end
end
end
%求小于阀域值均值
T0=S0/n0;
%求大于阀域值均值
T1=S1/n1;
%迭代至前后两次阀域值相差几乎为0时
if abs(T-((T0+T1)/2))<0.1
break;
else
%在阈值T下,迭代阈值的计算过程
T=(T0+T1)/2;
end
end
toc
T
i1=im2bw(Im,T/255); % 图像在最佳阈值下二值化
subplot(122)
imshow(i1)
title(['迭代后最终阈值输出:',num2str(T)]);
加速近端梯度算法(APG)
clc;
clear;
close all;
warning off;
addpath 'func\'
I1=imresize(imread('1.jpg'),[256,256]);
I2=imresize(imread('2.jpg'),[256,256]);
Init = I2;
figure;
subplot(131);
imshow(Init);
title('原始图');
tic
[A_hat,E_hat] = func_APG(double(rgb2gray(Init)),0.05,1000);
toc
subplot(132);
imshow(A_hat,[]);
title('low-rank结果');
subplot(133);
imshow(E_hat);
title('处理误差');
交替方向乘子算法(ADMM)
clc;
clear;
close all;
warning off;
addpath 'func\'
I1=imresize(imread('1.jpg'),[256,256]);
I2=imresize(imread('2.jpg'),[256,256]);
Init = I2;
figure;
subplot(121);
imshow(Init);
title('原始图');
%original image
tic
x = double(rgb2gray(Init));
[M,N] = size(x);
%FFT2
[H_FFT,HC_FFT]=func_hfft(x);
A = @(x) real(ifft2(H_FFT.*fft2(x)));
AT = @(x) real(ifft2(HC_FFT.*fft2(x)));
global calls;
calls = 0;
A = @(x) callcounter(A,x);
AT = @(x) callcounter(AT,x);
%观测矩阵
Ax = A(x);
Psig = norm(Ax,'fro')^2/(M*N);
y = Ax;
%parameters
lambda = 2.0e-2;
mu = lambda/10;
outeriters = 500;
tol = 1e-5;
%TV
Phi_TV = @(x) TVnorm(x);
chambolleit= 10;
Psi_TV = @(x,th) mex_vartotale(x,th,'itmax',chambolleit);
alpha = 1.2;
filter_FFT = 1./(abs(H_FFT).^2 + mu*alpha);
invLS = @(x) real(ifft2(filter_FFT.*fft2( x )));
invLS = @(x) callcounter(invLS,x);
[x_salsa, numA, numAt, objective1, distance, times1, mses1] = func_ADMM(y, A, lambda, 'MU', mu, 'AT', AT, 'StopCriterion', 1,'True_x', x, 'ToleranceA', tol, 'MAXITERA', outeriters, 'Psi', Psi_TV, 'Phi', Phi_TV, 'TVINITIALIZATION', 1, 'TViters', 10,'LS', invLS, 'VERBOSE', 0);
toc
subplot(122);
imshow(x_salsa,[]);
title('admm处理结果');