% This is for simulating the results of the single scale hybrid linear model 
% Description for the global variables:
% im - the original image
% imgVector - the vector data after image representation
% vectroMap - matrix used to mark the subspace label of each vector
% height - the height of the image
% width  - the width of the image
% wnd    - the size of the window used (wnd-by-wnd)
% c      - the number of components for the image
% vheiht - the height of the matrix vectroMap
% vwidth - the width of the matrix vectroMap
% blkpattern - Bool variable. true: block mode during image representation; false: pixel mode (using sliding window) image representation
clear;
global im imgVector vectorMap height width wnd c vheight vwidth blkpattern

% read image
load test.mat
im=mag;
[height width c]=size(im);
wnd = 8;
%block mode or pixel mode
blkpattern = true;

%sampling & dim. reduction
xd=img_represent();
display('data is ready, using GPCA');
% GPCA
[sampleLabels, groupBases, segmentationHistory, mergeLabelHistory] = entropy_gpca_vi(xd, 10, true, true);
display('grouping remaining vectors');
% groupe the remaining vectors 
grouping(sampleLabels);
imagesc(vectorMap);
% compress the groupped vectors
% procompress();