% ------------------------------------------------------------------------ 
%  Copyright (C)
%  Torr Vision Group (TVG)
%  University of Oxford - UK
% 
%  Qizhu Li <liqizhu@robots.ox.ac.uk>
%  August 2018
% ------------------------------------------------------------------------ 
% This file is part of the weakly-supervised training method presented in:
%    Qizhu Li*, Anurag Arnab*, Philip H.S. Torr,
%    "Weakly- and Semi-Supervised Panoptic Segmentation,"
%    European Conference on Computer Vision (ECCV) 2018.
% Please consider citing the paper if you use this code.
% ------------------------------------------------------------------------
% This function visualises the original prediction, original prediction 
% scores, processed semantic iterative GT, and generated instance 
% iterative GT.
%  INPUT:
%  - opts : options generated by get_opts.m
%  - results : results generated by the preceding code
%
%  DEMO:
%  - See scripts/run_sub.m
% ------------------------------------------------------------------------

function visualise_results_cam_mandg(opts, results)

if ~opts.visualise_results
    return;
end

f = figure('units','normalized','outerposition',[0 0 1 1], 'Visible', 'off');

ax(1) = subplot(2, 2, 1, 'replace');
imshow(results.pred, opts.cmap);
c(1) = colorbar(ax(1));
c(1).Limits = [0, 19];
c(1).Ticks = 0.5:1:18.5;
c(1).TickLabels = opts.objectNames;
c(1).FontSize = 8;
title(ax(1), '1. CAM prediction');

ax(2) = subplot(2, 2, 2, 'replace');
imshow(results.mandg_pred, results.mandg_cmap);
title(ax(2), '2. MCG&Grabcut Masks');

ax(3) = subplot(2, 2, 3, 'replace');
imshow(results.final_pred, opts.cmap);
c(3) = colorbar(ax(3));
c(3).Limits = [0, 19];
c(3).Ticks = 0.5:1:18.5;
c(3).TickLabels = opts.objectNames;
c(3).FontSize = 8;
title(ax(3), '3. Processed semantic GT');

ax(4) = subplot(2, 2, 4, 'replace');
imshow(results.ins_pred, opts.cmap);
c(4) = colorbar(ax(4));
num_instances = numel(results.ins_info);
c(4).Limits = [1, num_instances + 1];
c(4).Ticks = 1.5:1:(num_instances+0.5);
c(4).TickLabels = strcat(strsplit(num2str(extractfield(results.ins_info, 'ins_id'))), ...
    {': '}, extractfield(results.ins_info, 'name'));
c(4).FontSize = 8;
title(ax(4), '2. Generated instance GT');

f.Visible = 'on';

end