image-js
Version:
Image processing and manipulation in JavaScript
25 lines • 979 B
JavaScript
import { getClampFromTo } from '../../utils/clamp.js';
/**
* Generate an array of colors to draw the keypoints depending on their score or the matches depending on the distance.
* @param image - The source image.
* @param baseColor - The desired shade for the colors.
* @param options - Get score colors options.
* @returns Array of colors.
*/
export function getColors(image, baseColor, options = {}) {
const { nbShades = 6, minValueFactor = 0.2 } = options;
const maxValue = Math.max(...baseColor);
const minValue = maxValue * minValueFactor;
const interval = Math.floor((maxValue - minValue) / (nbShades - 1));
const clamp = getClampFromTo(0, image.maxValue);
const colors = [];
for (let i = 0; i < nbShades; i++) {
const color = [];
for (const channel of baseColor) {
color.push(clamp(channel - i * interval));
}
colors.push(color);
}
return colors;
}
//# sourceMappingURL=getColors.js.map