Tensorflow.js tf.image.transform() 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.transform() function is used to apply the specified transform(s) to the image(s).
tf.image.transform(image, transforms, interpolation?, fillMode?, fillValue?, outputShape?)
Parameters: This method accepts the following parameters:
- images: The stated 4d tensor, which is of configuration [batch, imageHeight, imageWidth, depth]. It can be of type tf.Tensor4D, TypedArray, or Array.
- transforms: The stated projective transform matrix or matrices. It is a 1d tensor of range 8 or else tensor of dimension N x 8. In case, a single row of transforms is [a0, a1, a2, b0 b1, b2, c0, c1], subsequently it plots the output point i.e. (x, y) into a modified input point i.e. (x’, y’) = ((a0 x + a1 y + a2) / k, (b0 x + b1 y + b2) / k), where k = c0 x + c1 y + 1. Moreover, the transforms are reversed in comparison to the transform plotting input points to the output points.
- interpolation: It is the stated interpolation mode. It can be of type ‘nearest’, or ‘bilinear’. It is optional and the by default value is ‘nearest’.
- fillMode: Here, the stated points beyond the margins of the input are filled in accordance with the stated mode. The mode is optional and can be of type ‘constant’, ‘reflect’, ‘wrap’, or ‘nearest’. The by default value is ‘constant’. In the ‘reflect‘ mode i.e. (d c b a | a b c d | d c b a ), the input is elongated by meditating around the verge of the utmost pixel. In the ‘constant‘ mode i.e. (k k k k | a b c d | k k k k), the input is elongated by stuffing every values beyond the verge along with the identical constant value k. In ‘wrap‘ mode i.e. (a b c d | a b c d | a b c d), the input is elongated by enclosing about the opposite edge. In ‘nearest‘ mode i.e. (a a a a | a b c d | d d d d), the input is elongated by the closest pixel.
- fillValue: It is a float that depicts the value which is to be filled beyond the edges, if the stated fillMode is ‘constant‘. It is optional and is of type number.
- outputShape: It is optional and is of type [number, number].
Return Value: It returns tf.Tensor4D object.
Example 1: Using a 4d tensor and a 2d tensor i.e. transforms.
Tensor [[[[0, 0 ], [1, 33]], [[1, 33], [8, 9 ]]]]
Example 2: Using an array of floats, interpolation, fillMode, fillValue, as well as outputShape.
Tensor [[[[3.3 , 3.4000001, 3.7 , 4 ], [4.3536587, 4.4536586, 4.6365857, 5.112195 ]], [[4.4178948, 4.5178947, 4.6936841, 5.1800003], [3.8970597, 4.0186343, 4.3869019, 4.721858 ]]]]