Last active
December 4, 2018 18:23
-
-
Save vabarbosa/3a457546d09ff1b743c38fba67adb89a to your computer and use it in GitHub Desktop.
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 colorMapUrl = '/assets/color-map.json' | |
// load the color-map file | |
const response = await fetch(colorMapUrl) | |
const colorMap = await response.json() | |
// get image width, height from output | |
const imageWidth = prediction.shape[2] | |
const imageHeight = prediction.shape[1] | |
// create a regular array from the model's output prediction (tensor) | |
const segMap = Array.from(prediction.dataSync()) | |
// create a new array with the corresponding segmentation colors | |
const segMapColor = segMap.map(seg => colorMap[seg]) | |
let data = [] | |
// load segmentation colors into format required for images | |
for (var i = 0; i < segMapColor.length; i++) { | |
data.push(segMapColor[i][0]) // red | |
data.push(segMapColor[i][1]) // green | |
data.push(segMapColor[i][2]) // blue | |
data.push(175) // alpha | |
} | |
// create an image with the segmentation color data | |
let imageData = new ImageData(imageWidth, imageHeight) | |
imageData.data.set(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment