Created
November 14, 2018 20:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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