clear all
close all
clc

SCDictionary=importdata('Dictionary/LDictionarySC_200its_3atoms_15DEC2013.mat');
RCDictionary=importdata('Dictionary/LDictionaryRC_200its_3atoms_15DEC2013.mat');

ImBlock=importdata('N00215.tif');


SampleSet=ExtractSamples(ImBlock,2);  
Y=SampleSet(:,3);

Y=Y/norm(Y);


SCCoefMatrix=OMP(SCDictionary,Y,3);
CoefInd = find(SCCoefMatrix);


RCCoefMatrix=OMP(RCDictionary,Y,3);
CoefIndRC = find(RCCoefMatrix);



DictE1=SCDictionary(:,CoefInd(1));
DictE2=SCDictionary(:,CoefInd(2));
DictE3=SCDictionary(:,CoefInd(3));

%---------------

DictE1RC=RCDictionary(:,CoefIndRC(1));
DictE2RC=RCDictionary(:,CoefIndRC(2));
DictE3RC=RCDictionary(:,CoefIndRC(3));


% PP=SCCoefMatrix(:,2045);

Coeff1=SCCoefMatrix(CoefInd(1));
Coeff2=SCCoefMatrix(CoefInd(2));
Coeff3=SCCoefMatrix(CoefInd(3));

%-------------

Coeff1RC=RCCoefMatrix(CoefIndRC(1));
Coeff2RC=RCCoefMatrix(CoefIndRC(2));
Coeff3RC=RCCoefMatrix(CoefIndRC(3));


Basis1=DictE1*Coeff1;
Basis2=DictE2*Coeff2;
Basis3=DictE3*Coeff3;

BasisSum=Basis1+Basis2+Basis3;


%------------

Basis1RC=DictE1RC*Coeff1RC;
Basis2RC=DictE2RC*Coeff2RC;
Basis3RC=DictE3RC*Coeff3RC;

BasisSumRC=Basis1RC+Basis2RC+Basis3RC;




Error=sqrt(sum((Y-BasisSum).^2)) % norm(Y) is already =1

ErrorRC=sqrt(sum((Y-BasisSumRC).^2)) % norm(Y) is already =1

xx=-8+1/4:1/4:8;

strSC=['RMSE= ',num2str(Error,3)];
strRC=['RMSE= ',num2str(ErrorRC,3)];

figure

subplot(1,2,1)
 plot(xx,Y,'k','LineWidth',2);
 hold on;
 plot(xx,BasisSum,'r','LineWidth',2);


plot(xx,Basis1,'b:','LineWidth',1.5);
plot(xx,Basis2,'b:','LineWidth',1.5);
plot(xx,Basis3,'b:','LineWidth',1.5);
text(-4, 0.4,strSC, 'Color', 'k');


xlim([-4.5 4.5]);
ylim([-0.1 0.5]);
xlabel('Pixel');
legend('Query Feature','Approximation','Weighted Atoms');

%------------

subplot(1,2,2)
 plot(xx,Y,'k','LineWidth',2);
 hold on;
 plot(xx,BasisSumRC,'r','LineWidth',2);


plot(xx,Basis1RC,'b:','LineWidth',1.5);
plot(xx,Basis2RC,'b:','LineWidth',1.5);
plot(xx,Basis3RC,'b:','LineWidth',1.5);
text(-4, 0.4,strRC, 'Color', 'k');

xlim([-4.5 4.5]);
ylim([-0.1 0.5]);
xlabel('Pixel');
legend('Query Feature','Approximation','Weighted Atoms');





