Trying to create a "heatmap" mask based off of the value of a RGB channel and the only way I can see doing this is with a nested for loop with an if/else chain.
This takes forever to do normally for larger images, so i have added this check / set to a Promise array.
I noticed that this finishes very quick, typically within a second, but the "set" doesn't stick.
const promises = [];
let height = 0;
let width = 0;
const heightMax = config.image.height;
const widthMax = config.image.width;
for (; height < heightMax; height++) {
for (; width < widthMax; width++) {
promises.push(new Promise((rslv) => {
const pixel = diffJpeg.at(height, width);
if (pixel.x >= 100) {
return rslv(imageMask.set(height, width, [ 123, 0, 255 ]));
} else if (pixel.x >= 80) {
return rslv(imageMask.set(height, width, [ 0, 123, 255 ]));
} else if (pixel.x >= 70) {
return rslv(imageMask.set(height, width, [ 0, 123, 255 ]));
} else if (pixel.x >= 60) {
return rslv(imageMask.set(height, width, [ 0, 112, 123 ]));
} else {
return rslv();
}
}));
}
}
Promise.all(promises).then(() => doSomething()).catch();
Trying to create a "heatmap" mask based off of the value of a RGB channel and the only way I can see doing this is with a nested for loop with an if/else chain.
This takes forever to do normally for larger images, so i have added this check / set to a Promise array.
I noticed that this finishes very quick, typically within a second, but the "set" doesn't stick.