import java.lang.Math.*; /** * TwoDArray is a data structure to represent a two-dimensional array * of complex numbers. ie The result of applying the 2D FFT to an image. * * @author Simon Horne. */ public class TwoDArray{ /** * The actual width of the image represented by the TwoDArray. */ public int width; /** * The actual height of the image represented by the TwoDArray. */ public int height; /** * Smallest value of 2^n such that the 2^n > width and 2^n > height. * The dimensions of the square 2D array storing the image. */ public int size; /** * The 2D array of complex numbers padded out with (0,0) * to 2^n width and height. */ public ComplexNumber [][] values; /** * Default no-arg constructor. */ public TwoDArray(){ } /** * Constructor that takes a TwoDArray and duplicates it exactly. * * @param a TwoDArray to be duplicated. */ public TwoDArray(TwoDArray a){ width = a.width; height = a.height; //System.out.println("NEW 2D 1 w: "+width+" height: "+height); size = a.size; values = new ComplexNumber[size][size]; for(int j=0;j=width)i2=i2%width; if(j2>=height)j2=j2%height; output[i][j] = input[i2][j2]; } } return output; } /** * Takes a 2D array of doubles representing an image and translates * and wraps the image to put the centre pixel at (0,0). * * @param input 2D array of doubles. * @return 2D array of doubles representing the new image. */ public double [][] DCToTopLeft(double [][] input){ double [][] output = new double [width][height]; int i2,j2; int x = width/2; int y = height/2; for(int j=0;j=width)i2=i2%width; if(j2>=height)j2=j2%height; output[i][j] = input[i2][j2]; } } return output; } public ComplexNumber [][] DCToTopLeft(ComplexNumber [][] input){ ComplexNumber [][] output = new ComplexNumber [width][height]; int i2,j2; int x = width/2; int y = height/2; for(int j=0;j=width)i2=i2%width; if(j2>=height)j2=j2%height; output[i][j] = input[i2][j2]; } } return output; } /** * Takes an array of doubles representing an image and translates * and wraps the image to put (0,0) the DC value in the centre of the image. * at (width/2,height/2) [because image runs -128..+127] * * @param input array of doubles. * @return array of doubles representing the new image. */ public double [] DCToCentre(double [] input){ double [][] input2 = new double [width][height]; double [][] output2 = new double [width][height]; double [] output = new double [width*height]; for(int j=0;j=width)i2=i2%width; if(j2>=height)j2=j2%height; output2[i][j] = input2[i2][j2]; } } for(int j=0;j