Open In App

Tensorflow.js tf.image.rotateWithOffset() 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.rotateWithOffset() function is used to rotate the input image tensor anticlockwise along with an alternative offset center of spin. At present, its accessible in the CPU, WebGL, as well as WASM backends.



Syntax:

tf.image.rotateWithOffset(image, radians, fillValue?, center?)

Parameters:  



Return Value: It returns tf.Tensor4D.

Example 1: In this example, we will be going to use a 4d tensor and radians parameter in tf.image.rotateWithOffset() function.




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

Output: 

Tensor
    [[[[0, 0 ],
       [0, 0 ]],

      [[0, 0 ],
       [1, 33]]]]

Example 2: In this example, we will be going to use an array of floats, fillValue, as well as center. 




// 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.rotateWithOffset() method and
// Printing output
tf.image.rotateWithOffset(arr, 5, [1, 2, 3], [1, 1]).print();

Output: 

Tensor
    [[[[1, 2, 3, 3],
       [1, 2, 3, 3]],

      [[1, 2, 3, 3],
       [1, 2, 3, 3]]]]

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

 


Article Tags :