我正在研究这个项目,我已经实现了字典以及OMP算法,现在我无法理解如何在lena image上实现。我正在这里提供我的代码。
%function [X_pr pp]=ompmod_pred2(D1,a1,sl,errorGoal)
%____________________________________________________
%prediction using (Aurelie method)
% D1=Dictionary;
%a1=image block of size (16X16);
%sl=sparsity label
%X_pr=predicted block
s=8;
%D=first 3:4 of D1
D=D1(1:3*s^2,:);
%D2=last 1:4 of D1
D2=D1(3*s^2+1:4*s^2,:);
%X_ac=block to be predicted
X_ac=a1(9:16,9:16);
%X1=reshape a1 to column
Y1=im2col(a1,[s,s],'distinct');
X1=im2col(Y1,[s^2,4],'distinct');
%X=first 3:4 of X1
X=X1(1:3*s^2,1);
%X2=last 1:4 of X1
X2=X1(3*s^2+1:4*s^2,1);
%___________________________________
%A2=calculation of solution vector at
%diffrent sparsity label using OMP
%___________________________________
[n,P]=size(X);
[n,K]=size(D);
E2 = errorGoal^2*n;
for s1=1:s1
maxNumCoef = s1;
A2(:,1)= zeros(size(D,2),size(X,2));
errorRes = X; % new entry
for k=1:1:P,
x=X(:,k);
residual=x;
indx = [];
a = [];
% currResNorm2 = sum(residual.^2); % creates problem for complex vectors
currResNorm2 = residual'*residual; %'
j = 0;
while currResNorm2>E2 & j < maxNumCoef,
j = j+1;
proj=D'*residual; %'
pos=find(abs(proj)==max(abs(proj)));
pos=pos(1);
indx(j)=pos;
z1=pinv(D(:,indx(1:j)));
a=pinv(D(:,indx(1:j)))*x;
residual=x-D(:,indx(1:j))*a;
% currResNorm2 = sum(residual.^2);
currResNorm2 = residual'*residual; %'
end;
if (length(indx)>0)
%_____________________________________
l1=length(indx);
for k1=1:l1
for k2=1:K
if k2==indx(1,k1)
A1(k2,k1)=a(k1,1);
else A1(k2,k1)=0;
end
end
if l1==1
A=A1;
else
A=sum(A1')';
end
%_______________________________________
errorRes(:,k)=residual; % new entry
end
end;
end
A2=[A2 A];
end
%________________________________________________
%X3=calculation of error at different sparsity label
l1=length(indx);
for k1=1:l1
X3(k1)=((D2*A2(:,k1+1))-X2)'*((D2*A2(:,k1+1))-X2); %'
end
% %________________________________________________
%pv=minimum error,pp=iteration
[pv pp]=min(X3);
%X_pr=predicted block
X_pr1=D2*A2(:,pp+1);
X_pr=col2im(X_pr1,[8 8],[8 8],'distinct');
%_________________________________________________
return;
这是我创建字典的代码。
function[D]=dict1(s)
%Generate DCT Dictionary of size (s^2 x s^2)
a=idct(eye(s));
for k1=1:s^2
if rem(k1,s)==0
b(:,(k1-1)*s+1:k1*s)=a(:,ceil(k1/s))*a(:,1)'; %'
else
b(:,(k1-1)*s+1:k1*s)=a(:,ceil(k1/s))*a(:,rem(k1,s))'; %'
end
end
D1=im2col(b,[s/2 s/2],'distinct');
D=im2col(D1,[s^2/4 4],'distinct');
end
其中s=16
请帮帮我。