To extract colors from an image that are suitable for generating schemes, use
the quantize
and score
libraries.
TODO: Insert here a diagram for image-to-colors extraction.
First, convert an image into an array of pixels in ARGB format. MCU does not provide this feature; please use the idiomatic method provided by your language.
If the image is larger than 128 × 128 pixels, please scale the image down to 128 × 128 before converting it to an array of pixels. This ensures the speed of processing.
For example, in Java, one may use the BufferedImage.getRGB
method:
import java.awt.image.BufferedImage;
class ImageUtils {
// ...
public static int[] imageToPixels(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
BufferedImage outputImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
return image.getRGB(0, 0, width, height, null, 0, width);
}
}
Once you have the array of pixels, pass it into QuantizerCelebi.quantize
provided by the quantize
library.
final quantizerResult = await QuantizerCelebi.quantize(pixels, maxColors);
QuantizerResult quantizerResult = QuantizerCelebi.quantize(pixels, maxColors);
const quantizerResult = QuantizerCelebi.quantize(pixels, maxColors);
QuantizerResult quantizer_result = QuantizeCelebi(pixels, max_colors);
let quantizerResult = QuantizerCelebi().quantize(pixels, maxColors)
The parameter maxColors
is a limit on the number of colors returned by the
quantizer. A reasonable default is 128.
Use the Score.score
method provided by the score
library to extract colors
that are suitable as seeds for color schemes, ranked by decreasing suitability.
final colors = Score.score(quantizerResult.colorToCount);
List<Integer> colors = Score.score(quantizerResult);
final colors = Score.score(quantizerResult);
std::vector<Argb> colors = RankedSuggestions(quantizer_result.color_to_count);
let colors = Score.score(quantizerResult.colorToCount)