From b2e22b5bb0796d3eacbb72e92a73e3ff3521f971 Mon Sep 17 00:00:00 2001
From: ben-burlingham
-
-You are given two true color images, the Source and the Palette. They do not necessarily have the same dimensions but it is guaranteed that their areas are the same, i.e. they have the same number of pixels.
+Pixel Palettes
-
-
-Tried my hand at this interesting challenge:
-
-
+ An interesting challenge from Codegolf Stack Exchange
+
-
+Problem Statement
-Your task is to create an algorithm that makes the most accurate looking copy of the Source by only using the pixels in the Palette. Each pixel in the Palette must be used exactly once in a unique position in this copy. The copy must have the same dimensions as the Source.
-
+ You are given two true color images, the Source and the Palette. They do not necessarily have the same dimensions but it is guaranteed that their areas are the same, i.e. they have the same number of pixels. +
+ Your task is to create an algorithm that makes the most accurate looking copy of the Source by only using the pixels in the Palette. Each pixel in the Palette must be used exactly once in a unique position in this copy. The copy must have the same dimensions as the Source. +
I developed a solution that takes a random pixel and uses a binary search to find a match in the target palette, weighted for the red component. Here are the results for that approach.
-Images are links, diagonals are originals. @@ -152,9 +149,13 @@ I developed a Source +
-var startTime = new Date().getTime();
+var startTime = new Date().getTime();
var fs = require("fs");
var pngjs = require("pngjs").PNG;