Skip to content

Instantly share code, notes, and snippets.

@Marina-Miranovich
Created November 14, 2018 20:49
Show Gist options
  • Save Marina-Miranovich/8cbc8f7448a73f3e04f57eb45b51f200 to your computer and use it in GitHub Desktop.
Save Marina-Miranovich/8cbc8f7448a73f3e04f57eb45b51f200 to your computer and use it in GitHub Desktop.
code_snippet_8 for "Playing Mortal Kombat with TensorFlow.js. Transfer learning and data augmentation" translation
const grayscale = (canvas: HTMLCanvasElement) => {
const imageData = canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height);
const data = imageData.data;
for (let i = 0; i < data.length; i += 4) {
const avg = (data[i] + data[i + 1] + data[i + 2]) / 3;
data[i] = avg;
data[i + 1] = avg;
data[i + 2] = avg;
}
canvas.getContext('2d').putImageData(imageData, 0, 0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment