How to create a mirror image using Java OpenCV library?

To create a mirror image

  • Read the required image using ImageIO.read() method.

  • Get the height and width of the image.

  • Create an empty buffered image to store the result

  • Using nested for loops traverse through each pixel in the image.

  • Iterate the width of the image from right to left.

  • Get the pixel value using the getRGB() method.

  • Set the pixel values to the result image object using the setRGB() method, by replacing the new width values.

Example

import java.io.File;
import java.io.IOException;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class MirrorImage {
   public static void main(String args[])throws IOException {
      //Reading the image
      File file= new File("D:\Images\tree.jpg");
      BufferedImage img = ImageIO.read(file);
      //Getting the height and with of the read image.
      int height = img.getHeight();
      int width = img.getWidth();
      //Creating Buffered Image to store the output
      BufferedImage res = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      for(int j = 0; j 

Input

Output

Updated on: 2020-04-09T07:17:16+05:30

846 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements