mirror of
https://github.com/wassname/keras-js.git
synced 2026-09-09 11:25:25 +08:00
add 1d-tensor to image conversion util function
This commit is contained in:
@@ -108,6 +108,19 @@ export function tensorMinMax (tensor) {
|
||||
return { min, max }
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes in a ndarray of shape [x]
|
||||
* and creates image data
|
||||
*/
|
||||
export function image1Dtensor (tensor) {
|
||||
const { min, max } = tensorMinMax(tensor)
|
||||
let imageData = new Uint8ClampedArray(tensor.size * 4)
|
||||
for (let i = 0, len = imageData.length; i < len; i += 4) {
|
||||
imageData[i + 3] = 255 * (tensor.data[i / 4] - min) / (max - min)
|
||||
}
|
||||
return new ImageData(imageData, tensor.shape[0], 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes in a ndarray of shape [x, y]
|
||||
* and creates image data
|
||||
|
||||
Reference in New Issue
Block a user