image-js
Version:
Image processing and manipulation in JavaScript
24 lines • 908 B
JavaScript
/**
* Find the min and max values of each channel of the image.
* @param image - Image to process.
* @returns An object with arrays of the min and max values.
*/
export function getMinMax(image) {
const min = new Array(image.channels).fill(image.maxValue);
const max = new Array(image.channels).fill(0);
for (let row = 0; row < image.height; row++) {
for (let column = 0; column < image.width; column++) {
for (let channel = 0; channel < image.channels; channel++) {
const currentValue = image.getValue(column, row, channel);
if (currentValue < min[channel]) {
min[channel] = currentValue;
}
if (currentValue > max[channel]) {
max[channel] = currentValue;
}
}
}
}
return { min, max };
}
//# sourceMappingURL=getMinMax.js.map