GeeksforGeeks App
Open App
Browser
Continue

# 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:

• images: The stated 4d tensor, which is of configuration [batch, imageHeight, imageWidth, depth]. It can be of type tf.Tensor4D, TypedArray, or Array.
• radians: The stated number of rotation. It is of type number.
• fillValue: It is the optional value which is used to fill in the vacant space that is unused after rotation. It can either be an individual grayscale value i.e. from 0 to 255, or else an array of three numerals i.e. [red, green, blue] indicating the red, green, as well as blue channels. The by default value is zero i.e. black channel. It can be of type number or [number, number, number].
• center: It is the stated center of spin. It can either be an individual value i.e. from 0 to 1, or else an array of two numerals i.e. [centerX, centerY]. The by default value is 0.5. It can be of type number or [number, number].

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.

## Javascript

 `// 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.

## 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.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]]]]```

My Personal Notes arrow_drop_up
Related Tutorials