
// Rotate.java
// Andrew Davison, ad@coe.psu.ac.th, April 2023

/* Two ways to rotate an image, one wih clipping and one
   without clipping.

   Usage:
     > compile Rotate.java
     > run Rotate <fnm>
   e.g.
     > run Rotate frankenburg-1918.png
     > run Rotate boats.png
*/

import java.util.*;

import ij.*;
import ij.io.*;
import ij.gui.*;
import ij.plugin.*;
import ij.plugin.filter.*;
import ij.process.*;


public class Rotate
{

  public static void main(String[] args)
  {
    if (args.length != 1) {
      System.out.println("Usage: run Rotate <fnm>");
      return;
    }

    ImagePlus imp = new ImagePlus(args[0]);
    imp.show();
    IJ.wait(2000);   // give time for user to see change

    ImageProcessor imProc = imp.getProcessor();

/*
    // rotation + no frame enlargement; clipping
    imProc.setBackgroundValue(0xffffff);   // white
    imProc.setInterpolationMethod(ImageProcessor.BILINEAR);
    imProc.rotate(15);   // clockwise; in degrees
    imp.updateAndDraw();
*/
    // rotation + frame enlargement; no clipping
    IJ.run("Colors...", "background=white");
    IJ.run(imp, "Rotate... ", 
          "angle=15 interpolation=Bilinear enlarge fill");
       // Image --> Transform --> Rotate

  } /* main */

}  // end of Rotate class
