function [xd]=img_represent()
global im imgVector vectorMap height width wnd c xx vheight vwidth blkpattern


l=round(wnd/2);
r=round(wnd/2-0.5);

wid=width-r-l+1;
hei=height-r-l+1;

if(blkpattern)%block-level vector
    vheight = floor(height/wnd);
    vwidth  = floor(width/wnd);
    imgVector=zeros(wnd*wnd*c,vheight*vwidth);
    vectorMap = NaN(vheight,vwidth);
    ri=randperm(vwidth*vheight)-1;
     for i=1:vheight
       for j=1:vwidth
           pos=1;
       %get the high-dim vector, here we have two
       %way:1.pixel-wise,2.color component-wise
       %piexel-wise
           for ii=1:wnd
               for jj=1:wnd
                   t(pos:pos+c-1,1)=double(im((i-1)*wnd+ii,(j-1)*wnd+jj,:));
                   pos=pos+c;
               end
           end
           imgVector(:,(i-1)*vwidth+j) = t;
       end
    end
else%pixel-level vector
    vheight = height-l-r+1;
    vwidth  = width-l-r+1;
    imgVector=zeros(wnd*wnd*c,vheight*vwidth);
    vectorMap = NaN(vheight,vwidth);
     ri=randperm(vwidth*vheight)-1;
    for i=l:height-r
       for j=l:width-r
           pos=1;
           %calculate the date vector for a specific pixel
           for ii=i-(l-1):i+r
               for jj=j-(l-1):j+r
                   t(pos:pos+c-1,1)=double(im(ii,jj,:));
                   pos=pos+c;
               end
           end
           imgVector(:,(i-l)*vwidth+j-l+1) = t;
       end
    end
end

num = min(1000,vheight*vwidth);

xx=zeros(wnd*wnd*c,num);
for idx=1:num    
    xx(:,idx) = imgVector(:,ri(idx)+1);
end


[K M]=size(xx);


x_mean=mean(xx')';

tmp = ones(1,num);
[u s v]=svd(xx-x_mean*tmp);


A=u;
for i=1:num
    B=xx(:,i)-x_mean;
    alpha(:,i)=A\B;
end


npc=8;
xd=zeros(npc,num);
for i=1:num
    xd(:,i)=alpha(1:npc,i);
end

