path(path,'Tensor Decomposition Toolbox - Release 1.2')
load dtensor13


% To do dimmensionality reduction use m_mode_svd_reduce function
[U,core]=m_mode_svd(dtensor,[2 3]);

l
% The first 6 view direction variations and first 5 illum. dir. variations

allim=[]; %collect all images in this matrix
for il=1:5,
 vwim=[];%collect view variation images in this matrix
 for v=1:6,
  im=reshape(core(1,v,il,:,:),80,107);
  mn=min(min(im));
  mx=max(max(im));
  mx=max(abs(mn),abs(mx)); % used for image normalization
  vwim=[vwim (im-mx)/(mx*2)]; 
 end;
 allim=[allim; vwim];
end;

figure; imshow(allim,[])

% Image Reconstructions - 8th viewpoint and 13th illumination
% U{2}(8,:)  is the 8 viewpoint representation
% U{3}(13,:) is the 13 illumination representation

im_vp8_il13=mode_m_prod(...
    mode_m_prod(core,U{2}(8,:),2),U{3}(13,:), 3);

% reconstruction with reduced illumination representation
% done through truncation
im_vp8_ril13=mode_m_prod(...
    mode_m_prod(core(:,:,1,:,:),U{2}(8,:),2),U{3}(13,1), 3);

figure;imshow([im_vp8_il13 im_vp8_ril13],[])