Published
Edited
Sep 23, 2019
13 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chromaBlend = (fgC, bgC, keyC, mask) => Math.max(fgC - mask * keyC, 0) + mask * bgC
Insert cell
chromaKeyMask = (r, g, b, keyCb, keyCr, tolA, tolB) => {
const cb = rgb2cb(r, g, b);
const cr = rgb2cr(r, g, b);
const d = Math.hypot(keyCb - cb, keyCr - cr);
return 1 - (d < tolA ? 0 : d > tolB ? 1 : (d - tolA) / (tolB - tolA));
}
Insert cell
rgb2cb = (r, g, b) => Math.round(128 - 0.168736 * r - 0.331264 * g + 0.5 * b)
Insert cell
rgb2cr = (r, g, b) => Math.round(128 + 0.5 * r - 0.418688 * g - 0.081312 * b)
Insert cell
Insert cell
Insert cell
Insert cell
keyColor = {
const k = 4 * (30 * foregroundImg.naturalWidth + 30); // fetch foreground pixel at [30, 30]
return fg.slice(k, k + 3);
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more