load('fig2.mat');

legText = {'TV-MAP-SLR at min. PET1 whole brain error';
           'ML-EM at min. PET1 whole brain error';
           'Double counts ML-EM at min. PET1 whole brain error';
           'TV-MAP-SLR at 200 iter. PET1 error';
           'ML-EM at 200 iter. PET1 error';
           'Double counts ML-EM at 200 iter. PET1 error'
           'TV-MAP-SLR at min. PET2 whole brain error';
           'ML-EM at min. PET2 whole brain error';
           'Double counts ML-EM at min. whole brain PET2 error';
           'TV-MAP-SLR at 200 iter. PET2 error';
           'ML-EM at 200 iter. PET2 error';
           'Double counts ML-EM at 200 iter. PET2 error'};
       
linStyles = {'-','--','-.'};
linMarkers = {'x','o','d'};
linWidth = 1.1;
markSize = 9;
linColors = {[0,0.5,0];
             [0.7,0,0];
             [0.7,0,0.7];
             [0,0,0.7]};
fontSize = 20;

fixedIt = 200;

numBtaTVMAPSLR = numel(bta_TVMAPSLR);

% find indices for minimum whole brain error
[~,mlemMinWholeBrainRmseIt] = min(mean(wholeBrainRmse_MLEM,2)); % minimum average error over PET1 and PET2
[~,mlemDoubleMinWholeBrainRmseIt] = min(mean(wholeBrainRmse_MLEM_double,2));

for bb = 1:numBtaTVMAPSLR
    % find the minimum error iteration for each beta value separately
    [~,TVMAPSLR_MinWholeBrainRmseIt(bb)] = min(mean(wholeBrainRmse_TVMAPSLR(:,bb,:),3));
    
    % get indices for each bta, scan combination
    TVMAPSLR_MinWholeBrainRmseInd(bb,1) = sub2ind(size(wholeBrainRmse_TVMAPSLR),TVMAPSLR_MinWholeBrainRmseIt(bb),bb,1);
    TVMAPSLR_MinWholeBrainRmseInd(bb,2) = sub2ind(size(wholeBrainRmse_TVMAPSLR),TVMAPSLR_MinWholeBrainRmseIt(bb),bb,2);
end

%%
figure
subplot(1,3,1)
% Tumour 1
% PET1
% minimum whole brain error 
plot(wholeBrainRmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,1)),Roi1Rmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,1)),'lineStyle',linStyles{1},'color',linColors{1},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(mlemMinWholeBrainRmseIt,1),Roi1Rmse_MLEM(mlemMinWholeBrainRmseIt,1),'lineStyle',linStyles{1},'color',linColors{1},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,1),Roi1Rmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,1),'lineStyle',linStyles{3},'color',linColors{1},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),
% end it (200)
plot(wholeBrainRmse_TVMAPSLR(fixedIt,:,1),Roi1Rmse_TVMAPSLR(fixedIt,:,1),'lineStyle',linStyles{1},'color',linColors{2},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(fixedIt,1),Roi1Rmse_MLEM(fixedIt,1),'lineStyle',linStyles{1},'color',linColors{2},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(fixedIt,1),Roi1Rmse_MLEM_double(fixedIt,1),'lineStyle',linStyles{3},'color',linColors{2},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),

% PET2
% minimum whole brain error 
plot(wholeBrainRmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,2)),Roi1Rmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,2)),'lineStyle',linStyles{1},'color',linColors{3},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(mlemMinWholeBrainRmseIt,2),Roi1Rmse_MLEM(mlemMinWholeBrainRmseIt,2),'lineStyle',linStyles{1},'color',linColors{3},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,2),Roi1Rmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,2),'lineStyle',linStyles{3},'color',linColors{3},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),

% end it (200)
plot(wholeBrainRmse_TVMAPSLR(fixedIt,:,2),Roi1Rmse_TVMAPSLR(fixedIt,:,2),'lineStyle',linStyles{1},'color',linColors{4},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(fixedIt,2),Roi1Rmse_MLEM(fixedIt,2),'lineStyle',linStyles{1},'color',linColors{4},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(fixedIt,2),Roi1Rmse_MLEM_double(fixedIt,2),'lineStyle',linStyles{3},'color',linColors{4},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),
xlim([25,65]),ylim([20,80])
xlabel('Whole-brain %RMSE'),ylabel('ROI1 %RMSE')
% title('')
set(findall(gca,'-property','FontSize'),'FontSize',fontSize)

subplot(1,3,2)
% Tumour 2
% PET1
plot(wholeBrainRmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,1)),Roi2Rmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,1)),'lineStyle',linStyles{1},'color',linColors{1},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(mlemMinWholeBrainRmseIt,1),Roi2Rmse_MLEM(mlemMinWholeBrainRmseIt,1),'lineStyle',linStyles{1},'color',linColors{1},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,1),Roi2Rmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,1),'lineStyle',linStyles{3},'color',linColors{1},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),
% end it (200)
plot(wholeBrainRmse_TVMAPSLR(fixedIt,:,1),Roi2Rmse_TVMAPSLR(fixedIt,:,1),'lineStyle',linStyles{1},'color',linColors{2},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(fixedIt,1),Roi2Rmse_MLEM(fixedIt,1),'lineStyle',linStyles{1},'color',linColors{2},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(fixedIt,1),Roi2Rmse_MLEM_double(fixedIt,1),'lineStyle',linStyles{3},'color',linColors{2},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),

% PET2
% minimum whole brain error 
plot(wholeBrainRmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,2)),Roi2Rmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,2)),'lineStyle',linStyles{1},'color',linColors{3},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(mlemMinWholeBrainRmseIt,2),Roi2Rmse_MLEM(mlemMinWholeBrainRmseIt,2),'lineStyle',linStyles{1},'color',linColors{3},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,2),Roi2Rmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,2),'lineStyle',linStyles{3},'color',linColors{3},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),

% end it (200)
plot(wholeBrainRmse_TVMAPSLR(fixedIt,:,2),Roi2Rmse_TVMAPSLR(fixedIt,:,2),'lineStyle',linStyles{1},'color',linColors{4},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(fixedIt,2),Roi2Rmse_MLEM(fixedIt,2),'lineStyle',linStyles{1},'color',linColors{4},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(fixedIt,2),Roi2Rmse_MLEM_double(fixedIt,2),'lineStyle',linStyles{3},'color',linColors{4},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),
xlim([25,65]),ylim([13,47])
xlabel('Whole-brain %RMSE'),ylabel('ROI2 %RMSE')
% title('')
set(findall(gca,'-property','FontSize'),'FontSize',fontSize)

subplot(1,3,3)
% PET1
plot(wholeBrainRmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,1)),Roi3Rmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,1)),'lineStyle',linStyles{1},'color',linColors{1},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(mlemMinWholeBrainRmseIt,1),Roi3Rmse_MLEM(mlemMinWholeBrainRmseIt,1),'lineStyle',linStyles{1},'color',linColors{1},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,1),Roi3Rmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,1),'lineStyle',linStyles{3},'color',linColors{1},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),
% end it (200)
plot(wholeBrainRmse_TVMAPSLR(fixedIt,:,1),Roi3Rmse_TVMAPSLR(fixedIt,:,1),'lineStyle',linStyles{1},'color',linColors{2},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(fixedIt,1),Roi3Rmse_MLEM(fixedIt,1),'lineStyle',linStyles{1},'color',linColors{2},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(fixedIt,1),Roi3Rmse_MLEM_double(fixedIt,1),'lineStyle',linStyles{3},'color',linColors{2},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),

% PET2
% minimum whole brain error 
plot(wholeBrainRmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,2)),Roi3Rmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,2)),'lineStyle',linStyles{1},'color',linColors{3},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(mlemMinWholeBrainRmseIt,2),Roi3Rmse_MLEM(mlemMinWholeBrainRmseIt,2),'lineStyle',linStyles{1},'color',linColors{3},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,2),Roi3Rmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,2),'lineStyle',linStyles{3},'color',linColors{3},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),

% end it (200)
plot(wholeBrainRmse_TVMAPSLR(fixedIt,:,2),Roi3Rmse_TVMAPSLR(fixedIt,:,2),'lineStyle',linStyles{1},'color',linColors{4},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(fixedIt,2),Roi3Rmse_MLEM(fixedIt,2),'lineStyle',linStyles{1},'color',linColors{4},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(fixedIt,2),Roi3Rmse_MLEM_double(fixedIt,2),'lineStyle',linStyles{3},'color',linColors{4},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),
xlabel('Whole-brain %RMSE'),ylabel('ROI3 %RMSE')
xlim([25,65]),ylim([20,90])
% title('')
set(findall(gca,'-property','FontSize'),'FontSize',fontSize)
%% add the legend separately
figure

plot(wholeBrainRmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,1)),Roi3Rmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,1)),'lineStyle',linStyles{1},'color',linColors{1},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(mlemMinWholeBrainRmseIt,1),Roi3Rmse_MLEM(mlemMinWholeBrainRmseIt,1),'lineStyle','none','color',linColors{1},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,1),Roi3Rmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,1),'lineStyle','none','color',linColors{1},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),
% end it (200)
plot(wholeBrainRmse_TVMAPSLR(fixedIt,:,1),Roi3Rmse_TVMAPSLR(fixedIt,:,1),'lineStyle',linStyles{1},'color',linColors{2},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(fixedIt,1),Roi3Rmse_MLEM(fixedIt,1),'lineStyle','none','color',linColors{2},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(fixedIt,1),Roi3Rmse_MLEM_double(fixedIt,1),'lineStyle','none','color',linColors{2},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),

% PET2
% minimum whole brain error 
plot(wholeBrainRmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,2)),Roi3Rmse_TVMAPSLR(TVMAPSLR_MinWholeBrainRmseInd(:,2)),'lineStyle',linStyles{1},'color',linColors{3},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(mlemMinWholeBrainRmseIt,2),Roi3Rmse_MLEM(mlemMinWholeBrainRmseIt,2),'lineStyle','none','color',linColors{3},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,2),Roi3Rmse_MLEM_double(mlemDoubleMinWholeBrainRmseIt,2),'lineStyle','none','color',linColors{3},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),

% end it (200)
plot(wholeBrainRmse_TVMAPSLR(fixedIt,:,2),Roi3Rmse_TVMAPSLR(fixedIt,:,2),'lineStyle',linStyles{1},'color',linColors{4},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{1}),hold on
plot(wholeBrainRmse_MLEM(fixedIt,2),Roi3Rmse_MLEM(fixedIt,2),'lineStyle','none','color',linColors{4},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{2}),
plot(wholeBrainRmse_MLEM_double(fixedIt,2),Roi3Rmse_MLEM_double(fixedIt,2),'lineStyle','none','color',linColors{4},'lineWidth',linWidth,'MarkerSize',markSize,'marker',linMarkers{3}),
legend(legText,'location','westoutside')
set(findall(gca,'-property','FontSize'),'FontSize',12)

set(gca,'visible','off')
set(get(gca,'children'),'visible','off')

