Sunday, January 18, 2026
HomeLanguagesJavascriptTensorflow.js tf.image.flipLeftRight() Function

Tensorflow.js tf.image.flipLeftRight() Function

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32474 POSTS0 COMMENTS
Milvus
118 POSTS0 COMMENTS
Nango Kala
6846 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12063 POSTS0 COMMENTS
Shaida Kate Naidoo
6985 POSTS0 COMMENTS
Ted Musemwa
7219 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6911 POSTS0 COMMENTS