Pankhuri Agarwal
Pankhuri Agarwal

Reputation: 794

Flip image left right in tensorflow js

I am new to tfjs and stuck on finding mirror of image. Is there any way to flip tensor in tensorflowjs, similar to - https://www.tensorflow.org/api_docs/python/tf/image/flip_left_right?

Upvotes: 2

Views: 734

Answers (1)

edkeveked
edkeveked

Reputation: 18401

tf.reverse can be used along the first axis

 flip = tf.tensor(
         [[[1.0, 2.0, 3.0],
           [4.0, 5.0, 6.0]],
          [[7.0, 8.0, 9.0],
          [10.0, 11.0, 12.0]]]).reverse(1)
          
flip.print()
<html>
  <head>
    <!-- Load TensorFlow.js -->
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"> </script>
  </head>

  <body>
  </body>
</html>

Since the version 2.3 there is now tf.image.flipLeftRight but it expects a 4d tensor for the image

Upvotes: 2

Related Questions