kernel = {
const gpu = new GPU.GPU();
return gpu.createKernel(function(foreground, background) {
let pixel = foreground[this.thread.y][this.thread.x];
const max = Math.max(Math.max(pixel[0], pixel[1]), pixel[2]);
const min = Math.min(Math.min(pixel[0], pixel[1]), pixel[2]);
const green = pixel[1];
const replace =
(green !== min)
&& (
green === max
|| (max - green) < this.constants.maxDifference
)
&& (max - min) > this.constants.minDifference;
if (replace) {
pixel = background[this.thread.y][this.thread.x];
}
this.color(pixel[0], pixel[1], pixel[2], 1);
}, {
output: [image.width, image.height],
graphical: true,
argumentTypes: {
foreground: 'HTMLImage',
background: 'HTMLImage'
},
constants: {
maxDifference: 8 / 255,
minDifference: 96 / 255,
}
});
}