Add a --show-final-score to output the final image quality score.

This is useful when used as part of an image repository build
pipeline, to avoid replacing existing images if the new score is
higher.

Hide intermediate output behind --verbose
This commit is contained in:
kris 2021-11-24 15:49:56 +00:00
parent 0036ee9522
commit 9a77af37aa

View File

@ -143,7 +143,6 @@ class ClusterPalette:
outer_iterations_since_improvement = 0 outer_iterations_since_improvement = 0
while outer_iterations_since_improvement < max_outer_iterations: while outer_iterations_since_improvement < max_outer_iterations:
print("New iteration")
inner_iterations_since_improvement = 0 inner_iterations_since_improvement = 0
self._palette_lines = self._init_palette_lines() self._palette_lines = self._init_palette_lines()
@ -336,6 +335,10 @@ def main():
help='Whether to save a .PNG rendering of the output image (default: ' help='Whether to save a .PNG rendering of the output image (default: '
'True)' 'True)'
) )
parser.add_argument(
'--show-final-score', type=bool, default=False,
help='Whether to output the final image quality score (default: False)'
)
args = parser.parse_args() args = parser.parse_args()
if args.lookahead < 1: if args.lookahead < 1:
parser.error('--lookahead must be at least 1') parser.error('--lookahead must be at least 1')
@ -382,7 +385,7 @@ def main():
palettes_rgb12_iigs, palettes_linear_rgb) in cluster_palette.iterate( palettes_rgb12_iigs, palettes_linear_rgb) in cluster_palette.iterate(
penalty, inner_iterations, outer_iterations): penalty, inner_iterations, outer_iterations):
if total_image_error is not None: if args.verbose and total_image_error is not None:
print("Improved quality +%f%% (%f)" % ( print("Improved quality +%f%% (%f)" % (
(1 - new_total_image_error / total_image_error) * 100, (1 - new_total_image_error / total_image_error) * 100,
new_total_image_error)) new_total_image_error))
@ -427,6 +430,7 @@ def main():
unique_colours = np.unique( unique_colours = np.unique(
palettes_rgb12_iigs.reshape(-1, 3), axis=0).shape[0] palettes_rgb12_iigs.reshape(-1, 3), axis=0).shape[0]
if args.verbose:
print("%d unique colours" % unique_colours) print("%d unique colours" % unique_colours)
seq += 1 seq += 1
@ -443,6 +447,8 @@ def main():
with open(args.output, "wb") as f: with open(args.output, "wb") as f:
f.write(bytes(screen.memory)) f.write(bytes(screen.memory))
if args.show_final_score:
print("FINAL_SCORE:", total_image_error)
if __name__ == "__main__": if __name__ == "__main__":