Open In App

Tensorflow.js tf.image.flipLeftRight() Function

Last Updated : 29 Jul, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Tensorflow.js is an open-source library developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.

The .image.flipLeftRight() function is used to flip the stated image from left hand side to the right hand side. For the time being its accessible in the CPU, WebGL, as well as WASM backends.

Syntax:

tf.image.flipLeftRight(image)

Parameters:  

  • image: It is the stated 4d tensor of structure [batch, imageHeight, imageWidth, depth]. It can be of type tf.Tensor4D, TypedArray, or Array.

Return Value: It returns the tf.Tensor4D object.

Example 1: In this example, we are going to see the use of using a 4d tensor in Tensorflow.js tf.image.flipLeftRight() function.

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling image.flipLeftRight() method and
// Printing output
tf.image.flipLeftRight(tf.tensor4d([[
  
  [[4, 7], [21, 9]],
  
  [[8, 9], [1, 5]]
  
]])).print();


Output:

Tensor
    [[[[21, 9],
       [4 , 7]],

      [[1 , 5],
       [8 , 9]]]]

Example 2: In this example, we are going to see the use of an array of floats inside Tensorflow.js tf.image.flipLeftRight() function.

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining an array of floats
const arr = [[
  
  [[1.1, 1.7, 1.5, 1.1], 
  [1.7, 1.9, 8.1, 6.3]],
  [[3.3, 3.4, 3.7, 4.0], 
  [5.1, 5.2, 5.3, 5.9]]
  
]];
  
// Calling image.flipLeftRight() method and
// Printing output
tf.image.flipLeftRight(arr).print();


Output:

Tensor
    [[[[1.7      , 1.9      , 8.1000004, 6.3000002],
       [1.1      , 1.7      , 1.5      , 1.1      ]],

      [[5.0999999, 5.1999998, 5.3000002, 5.9000001],
       [3.3      , 3.4000001, 3.7      , 4        ]]]]

Reference: https://js.tensorflow.org/api/latest/#image.flipLeftRight



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads