From 61fd01dc268cbeb6c614e7925f86779737ce97d2 Mon Sep 17 00:00:00 2001 From: Ben Heasly <benjamin.heasly@gmail.com> Date: Tue, 7 Feb 2017 11:13:02 -0500 Subject: [PATCH] refactor rtbRunEpicComparison around new, smaller functions --- .../rtbPlotManyRecipeComparisons.m | 33 +++++++---- Test/Interactive/rtbPlotRenderingComparison.m | 4 ++ Test/Interactive/rtbRunEpicComparison.m | 56 +++++++++++++++++-- 3 files changed, 77 insertions(+), 16 deletions(-) diff --git a/Test/Interactive/rtbPlotManyRecipeComparisons.m b/Test/Interactive/rtbPlotManyRecipeComparisons.m index 36944bd..5a6a1c6 100644 --- a/Test/Interactive/rtbPlotManyRecipeComparisons.m +++ b/Test/Interactive/rtbPlotManyRecipeComparisons.m @@ -13,6 +13,7 @@ parser = inputParser(); parser.KeepUnmatched = true; parser.addRequired('comparisons', @isstruct); parser.addParameter('fig', figure()); +parser.addParameter('figureWidth', 1000, @isnumeric); parser.addParameter('nRows', 25, @isnumeric); parser.addParameter('correlationMin', 0.8, @isnumeric); parser.addParameter('correlationStep', 0.05, @isnumeric); @@ -21,6 +22,7 @@ parser.addParameter('errorStep', 0.5, @isnumeric); parser.parse(comparisons, varargin{:}); comparisons = parser.Results.comparisons; fig = parser.Results.fig; +figureWidth = parser.Results.figureWidth; nRows = parser.Results.nRows; correlationMin = parser.Results.correlationMin; correlationStep = parser.Results.correlationStep; @@ -28,22 +30,26 @@ errorMax = parser.Results.errorMax; errorStep = parser.Results.errorStep; -%% Summarize only good comparisons. +%% Sort the summary by size of error. goodComparisons = comparisons([comparisons.isGoodComparison]); +relNormDiff = [goodComparisons.relNormDiff]; +errorStat = [relNormDiff.max]; +[~, order] = sort(errorStat); +goodComparisons = goodComparisons(order); + +%% Set up the figure. figureName = sprintf('Summary of %d rendering comparisons', ... numel(goodComparisons)); set(fig, ... 'Name', figureName, ... 'NumberTitle', 'off'); - -%% Sort the summary by size of error. -relNormDiff = [goodComparisons.relNormDiff]; -errorStat = [relNormDiff.max]; -[~, order] = sort(errorStat); -goodComparisons = goodComparisons(order); - +position = get(fig, 'Position'); +if position(3) < figureWidth + position(3) = figureWidth; + set(fig, 'Position', position); +end %% Summary of correlation coefficients. correlationTicks = correlationMin : correlationStep : 1; @@ -68,7 +74,14 @@ line(correlation, 1:nLines, ... 'LineStyle', 'none', ... 'Marker', 'o', ... 'Color', [0 0 1]) -title(ax(1), 'correlation'); +xlabel(ax(1), 'correlation'); + + +%% Overall title. +name = sprintf('%s vs %s', ... + goodComparisons(1).renderingA.sourceFolder, ... + goodComparisons(1).renderingB.sourceFolder); +title(ax(1), name, 'Interpreter', 'none'); %% Summary of mean and max subpixel differences. @@ -101,7 +114,7 @@ line(means, 1:nLines, ... 'Marker', 'o', ... 'Color', [0 0 0]) legend(ax(2), 'max', 'mean', 'Location', 'northeast'); -title(ax(2), 'relative diff'); +xlabel(ax(2), 'relative diff'); %% Let the user scroll both axes at the same time. diff --git a/Test/Interactive/rtbPlotRenderingComparison.m b/Test/Interactive/rtbPlotRenderingComparison.m index dc87063..185bb1e 100644 --- a/Test/Interactive/rtbPlotRenderingComparison.m +++ b/Test/Interactive/rtbPlotRenderingComparison.m @@ -46,10 +46,14 @@ set(fig, ... ax = subplot(2, 2, 2, 'Parent', fig); imshow(uint8(rgbA), 'Parent', ax); title(ax, 'A'); +xlabel(ax, comparison.renderingA.sourceFolder, ... + 'Interpreter', 'none'); ax = subplot(2, 2, 3, 'Parent', fig); imshow(uint8(rgbB), 'Parent', ax); title(ax, 'B'); +xlabel(ax, comparison.renderingB.sourceFolder, ... + 'Interpreter', 'none'); ax = subplot(2, 2, 1, 'Parent', fig); imshow(uint8(rgbAminusB), 'Parent', ax); diff --git a/Test/Interactive/rtbRunEpicComparison.m b/Test/Interactive/rtbRunEpicComparison.m index 8df59e0..eb8922d 100644 --- a/Test/Interactive/rtbRunEpicComparison.m +++ b/Test/Interactive/rtbRunEpicComparison.m @@ -45,7 +45,7 @@ parser.addRequired('folderB', @ischar); parser.addParameter('plotSummary', true, @islogical); parser.addParameter('closeSummary', false, @islogical); parser.addParameter('plotImages', false, @islogical); -parser.addParameter('closeImages', true, @islogical); +parser.addParameter('closeImages', false, @islogical); parser.addParameter('figureFolder', '', @ischar); parser.parse(folderA, folderB, varargin{:}); folderA = parser.Results.folderA; @@ -56,11 +56,55 @@ plotImages = parser.Results.plotImages; closeImages = parser.Results.closeImages; figureFolder = parser.Results.figureFolder; -matchInfo = []; -unmatchedA = {}; -unmatchedB = {}; +figs = []; +%% Run the grand comparison. +[comparisons, matchInfo] = rtbCompareManyRecipes(folderA, folderB, ... + varargin{:}); + + +%% Plot the summary. +if plotSummary + summaryFig = rtbPlotManyRecipeComparisons(comparisons, ... + varargin{:}); + + if ~isempty(figureFolder); + imageFileName = fullfile(figureFolder, 'epic-summary'); + saveFigure(summaryFig, imageFileName); + end + + if closeSummary + close(summaryFig); + else + figs = [figs summaryFig]; + end +end + + +%% Plot the detail images for each rendering. +if plotImages + nComparisons = numel(comparisons); + imageFigs = cell(1, nComparisons); + for cc = 1:nComparisons + imageFig = rtbPlotRenderingComparison(comparisons(cc), ... + varargin{:}); + + if ~isempty(figureFolder); + identifier = comparisons(cc).renderingA.identifier; + imageFileName = fullfile(figureFolder, identifier); + saveFigure(imageFig, imageFileName); + end + + if closeImages + close(imageFig); + else + imageFigs{cc} = imageFig; + end + end + figs = [figs imageFigs{:}]; +end + %% Save a figure to file, watch out for things like uicontrols. function saveFigure(fig, fileName) @@ -79,10 +123,10 @@ if 7 ~= exist(filePath, 'dir') end % save a png and a figure -figName = fullfile(imageCompPath, [fileName '.fig']); +figName = fullfile(filePath, [fileName '.fig']); saveas(fig, figName, 'fig'); -pngName = fullfile(imageCompPath, [fileName '.png']); +pngName = fullfile(filePath, [fileName '.png']); set(fig, 'PaperPositionMode', 'auto'); saveas(fig, pngName, 'png'); -- GitLab