Skip to content

Instantly share code, notes, and snippets.

@arielmagbanua
Created September 12, 2020 11:52
Show Gist options
  • Save arielmagbanua/1bd6ec5700608102f81eb471c6effeea to your computer and use it in GitHub Desktop.
Save arielmagbanua/1bd6ec5700608102f81eb471c6effeea to your computer and use it in GitHub Desktop.
TensorFlowJs Advanced Manipulation rg blind
// TensorPlayground.com
// https://images.unsplash.com/photo-1506108928571-9f4b11ba3f10?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80
// INPUT TENSOR SHAPE: [901,1350,3]
(tf, aTensor) => {
const height = aTensor.shape[0]
const width = aTensor.shape[1]
const halfHeight = (height - 1) / 2
console.log(halfHeight)
const [red, green, blue] = aTensor.split(3, 2)
// stack red and green + average
const rg = tf.mean(tf.stack([red, green]), 0).asType("int32")
// recostruct rgb
const rgb = tf.concat([rg, rg, blue], 2)
const rgbUpperHalf = rgb.slice(0, [halfHeight + 65, width, 3])
const lowerSliceStart = halfHeight + 65
const lowerHeightSlice = halfHeight + 1 - 65;
const originalLowerHalf = aTensor.slice([lowerSliceStart, 0], [lowerHeightSlice, width, 3])
const tigerConcat = rgbUpperHalf.concat(originalLowerHalf, 0)
return tigerConcat
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment