% EMP8_ex3         Test EMP8_swap.m  (script file)

clear all;
mfile = 'EMP8_ex3';

tim = 2;  
lambda = 2;
bF8percent = 70; 
sigma = 6;
% bw = -1  -->  [3,5,8,13,21,34]
opt = struct('verbose',1, 'useRand',false, 'bw',-1, ...
    'lambda',lambda,'bF8percent',bF8percent,'maxLoop',25);

Uim = teximage(100+tim,[],0,4);  % read test image, and display it
[I,J] = size(Uim); 

s = EMP8_argin(tim, sigma, tim, opt, 'bw',-1);
[L1,c1] = EMP8_swap(s);
figure(1); clf;  % and plot results in figure 1
figTitle = ['Labeling of test image ',int2str(tim),' after using EMP8-swap, swUpq=1.'];
LIS_plotcol(reshape(L1,I,J), figTitle, c1.errorRate, -1, c1.Etot, c1.Edata, c1.E4+c1.E8);

% make cost reduction factors for edges similar to 
% ( ... 'swUpq',3, 'Uim',tim, 'Utab',[1,255,0], ... )
Upq = zeros(I,J,4);
Upq(:,:,1) = Uim - [Uim(1,:); Uim(2:I,1),Uim(1:(I-1),1:(J-1))];
Upq(:,:,2) = Uim - [Uim(:,1),Uim(:,1:(J-1))];
Upq(:,:,3) = Uim - [Uim(:,1),[Uim(2:I,1:(J-1));Uim(I,2:J)]];
Upq(:,:,4) = Uim - [Uim(1,:);Uim(1:(I-1),:)];
Upq = abs(Upq); Upq = 1 - Upq/max(Upq(:));
s = EMP8_argin(s, 'swUpq',2, 'Upq',Upq);
[L2,c2] = EMP8_swap(s);
figure(2); clf;  % and plot results in figure 2
figTitle = ['Labeling of test image ',int2str(tim),' after using EMP8-swap, swUpq=2.'];
LIS_plotcol(reshape(L2,I,J), figTitle, c2.errorRate, -1, c2.Etot, c2.Edata, c2.E4+c2.E8);

% now calculate cost reduction factors for edges from image after defined rules
s = EMP8_argin(s, 'Li',sigma, 'swUpq',3, 'Upq',uint16([]), 'Uim',tim, 'Utab',[2,120,0.3]);
[L3,c3] = EMP8_swap(s);
figure(3); clf;
figTitle = ['Labeling of test image ',int2str(tim),' after using EMP8-swap, swUpq=3.'];
LIS_plotcol(reshape(L3,I,J), figTitle, c3.errorRate, -1, c3.Etot, c3.Edata, c3.E4+c3.E8);
