image-js
Version:
Image processing and manipulation in JavaScript
32 lines • 1.37 kB
JavaScript
import { hsvToRgb } from '../hsvToRgb.js';
import { rgbToNumber } from '../rgbToNumber.js';
/**
* Return a map where ROIs are different shades of red (positive) or blue (negative) depending on the ROI index. It it the saturation of the HSV color model that is varied.
* @param options - Get temperature map options.
* @returns The colored map.
*/
export function getSaturationMap(options) {
const { nbNegative, nbPositive, roiKind = 'bw', whiteHue = 0, blackHue = 240, } = options;
const colorMap = new Uint32Array(nbNegative + nbPositive + 1);
const range = 255 - 63; // saturation range for good contrast
const negativeStep = range / nbNegative;
const positiveStep = range / nbPositive;
// negative values
let counter = 0;
if (roiKind === 'bw' || roiKind === 'black') {
for (let i = -nbNegative; i < 0; i++) {
const hsv = [blackHue, 255 - counter++ * negativeStep, 255];
colorMap[i + nbNegative] = rgbToNumber(hsvToRgb(hsv));
}
}
// positive values
counter = 0;
if (roiKind === 'bw' || roiKind === 'white') {
for (let i = 1; i <= nbPositive; i++) {
const hsv = [whiteHue, 255 - counter++ * positiveStep, 255];
colorMap[i + nbNegative] = rgbToNumber(hsvToRgb(hsv));
}
}
return colorMap;
}
//# sourceMappingURL=getSaturationMap.js.map