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

Function draw

mnist/ui.js:96–111  ·  view source on GitHub ↗
(image, canvas)

Source from the content-addressed store, hash-verified

94}
95
96export function draw(image, canvas) {
97 const [width, height] = [28, 28];
98 canvas.width = width;
99 canvas.height = height;
100 const ctx = canvas.getContext('2d');
101 const imageData = new ImageData(width, height);
102 const data = image.dataSync();
103 for (let i = 0; i < height * width; ++i) {
104 const j = i * 4;
105 imageData.data[j + 0] = data[i] * 255;
106 imageData.data[j + 1] = data[i] * 255;
107 imageData.data[j + 2] = data[i] * 255;
108 imageData.data[j + 3] = 255;
109 }
110 ctx.putImageData(imageData, 0, 0);
111}
112
113export function getModelTypeId() {
114 return document.getElementById('model-type').value;

Callers 1

showTestResultsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected