/**          Test program for DIA to read in pgm image,
 *           take centred FFT, display Power Spectrum and plot
 *           out vertical and horizontal lines. using SimpleGraph
 *
 *           Must set env variable 
 *           export LD_LIBRARY_PATH=/ifp/java/lib/
 *           before running this programe.
 */
import ptolemy.plot.*;                    // The pt plot classes
import uk.ac.ed.ph.signal.*;             // Import signal classes
import jfftw.*;              // Import jfftw class (gives Complex)

public class FourierImage {
    public static void main(String args[]) {
	
	//           Check there is a file name given
	if (args.length == 0) {
	    System.err.println("Usage: java ImageTest filename");
	    System.exit(1);
	}
	String file = args[0];

	//        Read in image from pgm image to ComplexImage type

	ComplexImage image = new ComplexImage(RealImage.fromPGMFile(file));
	
	//        Printout image imformation
	System.out.println("Before transform\n" + image);

	//        Form centred FFT and print out imfo
	image.centreFourier();
	System.out.println("After transform\n" + image);
	
	//         Get RealImage, being the LOG_POWER
	RealImage pict = image.getRealImage(Complex.LOG_POWER);

	//         Get the real stats of the pict and display
	RealStatistics stats = new RealStatistics(pict);
	System.out.println("Image stats are: " + stats);


	//          Open a display panel and display the pict
	ImageFrame display = new ImageFrame("Power Spectrum");

	//          Add image specifying min/max pixel values
	display.addImage(pict);
	display.centre();                  // Centre on screen

	//         Get the row/col through centre as realsignals
	RealSignal row = pict.getRow(pict.getHeight()/2);
	RealSignal col = pict.getColumn(pict.getWidth()/2);

	//          Make a new plot
	Plot plot = new Plot();
	row.toPlot(plot,0,true);
	col.toPlot(plot,1,true);

	PlotFrame frame = new PlotFrame("FT",plot);
	frame.setSize(600,400);
	frame.setVisible(true);
	
    }
}
