MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / draw

Function draw

mnist-core/ui.js:80–95  ·  view source on GitHub ↗
(image, canvas)

Source from the content-addressed store, hash-verified

78}
79
80export function draw(image, canvas) {
81 const [width, height] = [28, 28];
82 canvas.width = width;
83 canvas.height = height;
84 const ctx = canvas.getContext('2d');
85 const imageData = new ImageData(width, height);
86 const data = image.dataSync();
87 for (let i = 0; i < height * width; ++i) {
88 const j = i * 4;
89 imageData.data[j + 0] = data[i] * 255;
90 imageData.data[j + 1] = data[i] * 255;
91 imageData.data[j + 2] = data[i] * 255;
92 imageData.data[j + 3] = 255;
93 }
94 ctx.putImageData(imageData, 0, 0);
95}

Callers 1

showTestResultsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected