%%%  Spatial_Saliency  %%%%
%%%  2010-sept-15 %%%%
%%%  Li Jian      %%%%
%%%  To use entropy as weight for each channel.
%%
function mySMap2=Spatial_saliency(inImg);
inImg=double(inImg);
inImg=inImg/max(max(max(inImg)));
r=inImg(:,:,1);g=inImg(:,:,2);b=inImg(:,:,3);
r=imresize(r,[128,128],'bilinear');g=imresize(g,[128,128],'bilinear');b=imresize(b,[128,128],'bilinear');

inImg=zeros(128,128,3);
inImg(:,:,1)=r;
inImg(:,:,2)=g;
inImg(:,:,3)=b;
[m,n,nn]=size(inImg);
%%
D=zeros(192,(m-7)*(n-7));
k=0;
for j=1:m-7
    for i=1:n-7
        k=k+1;
        buf=inImg(i:i+7,j:j+7,:);
        D(:,k)=buf(:);
    end
end
%%
load ICA_FILTERS.mat;
S=W*D;S=S/max(max(S));S=uint8(S*255);

Entro=0;
buffer=zeros(128);
for i=1:size(S,1)
    buff=S(i,:);
    buff=reshape(abs(buff),128-7,128-7)';
    buffer(5:125,5:125)=buff;
    Entro(i)=entropy2((buffer));
end
Entro=exp(-Entro-min(-Entro))-1;
Entro=Entro/max(Entro);

S1= (1*Entro)*(abs(double(S)).^1);
mySMap=reshape(S1,128-7,128-7)';

%% Visualization
mySMap = abs(mySMap').^1;
mySMap=mat2gray(mySMap);
mySMap2=zeros(128);
mySMap2(5:125,5:125)=mySMap;