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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more