Class TwoDArray

java.lang.Object
  |
  +--TwoDArray

public class TwoDArray
extends java.lang.Object

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.

Field Summary
 int height
          The actual height of the image represented by the TwoDArray.
 int size
          Smallest value of 2^n such that the 2^n > width and 2^n > height.
 ComplexNumber[][] values
          The 2D array of complex numbers padded out with (0,0) to 2^n width and height.
 int width
          The actual width of the image represented by the TwoDArray.
 
Constructor Summary
TwoDArray()
          Default no-arg constructor.
TwoDArray(ComplexNumber[][] v, int w, int h)
          Constructor taking 2D array of complex numbers, width and height.
TwoDArray(int s)
          Constructor that takes a single dimension, generates an appropriate size and sets up a size x size array of (0,0) complex numbers.
TwoDArray(int[][] v, int w, int h)
          Constructor taking 2D int array of pixels values, width and height, sets values to (x,0) for each pixel x.
TwoDArray(int[] p, int w, int h)
          Constructor taking int array of pixel values and width and height of the image represented by the array of pixels, sets values to (x,0) for each pixel x.
TwoDArray(int w, int h)
          Constructor that takes a width and a height, generates the appropriate size values and then sets up an array of (0,0) complex numbers.
TwoDArray(TwoDArray a)
          Constructor that takes a TwoDArray and duplicates it exactly.
 
Method Summary
 double[] DCToCentre(double[] input)
          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.
 double[][] DCToCentre(double[][] input)
          Takes a 2D 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.
 ComplexNumber[][] DCToTopLeft(ComplexNumber[][] input)
           
 double[][] DCToTopLeft(double[][] input)
          Takes a 2D array of doubles representing an image and translates and wraps the image to put the centre pixel at (0,0).
 ComplexNumber[] getColumn(int n)
          Takes a column number and returns an array containing the complex numbers in that column.
 double[] getImaginary()
          Method to extract the imaginary parts from a TwoDArray.
 double[] getMagnitude()
          Method to extract the magnitude of each element from a TwoDArray.
 double[] getPhase()
          Method to extract the phase angle of each element from a TwoDArray.
 double[] getReal()
          Method to extract the real parts from a TwoDArray.
 ComplexNumber[] getRow(int n)
          Takes a row number and returns an array containing the complex numbers in that row.
 void putColumn(int n, ComplexNumber[] c)
          Takes a column number and an array of complex numbers and replaces that column with the new data.
 void putRow(int n, ComplexNumber[] c)
          Takes a row number and an array of complex numbers and replaces that row with the new data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

width

public int width
The actual width of the image represented by the TwoDArray.

height

public int height
The actual height of the image represented by the TwoDArray.

size

public int size
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.

values

public ComplexNumber[][] values
The 2D array of complex numbers padded out with (0,0) to 2^n width and height.
Constructor Detail

TwoDArray

public TwoDArray()
Default no-arg constructor.

TwoDArray

public TwoDArray(TwoDArray a)
Constructor that takes a TwoDArray and duplicates it exactly.
Parameters:
a - TwoDArray to be duplicated.

TwoDArray

public TwoDArray(int w,
                 int h)
Constructor that takes a width and a height, generates the appropriate size values and then sets up an array of (0,0) complex numbers.
Parameters:
w - Width of the new TwoDArray.
h - Height of the new TwoDArray.

TwoDArray

public TwoDArray(int s)
Constructor that takes a single dimension, generates an appropriate size and sets up a size x size array of (0,0) complex numbers.
Parameters:
s - Width or height of new TwoDArray.

TwoDArray

public TwoDArray(int[] p,
                 int w,
                 int h)
Constructor taking int array of pixel values and width and height of the image represented by the array of pixels, sets values to (x,0) for each pixel x.
Parameters:
p - int array of pixel values.
w - Width of image.
h - Height of image.

TwoDArray

public TwoDArray(int[][] v,
                 int w,
                 int h)
Constructor taking 2D int array of pixels values, width and height, sets values to (x,0) for each pixel x.
Parameters:
v - 2D array of pixel values.
w - Width of image.
h - Height of image.

TwoDArray

public TwoDArray(ComplexNumber[][] v,
                 int w,
                 int h)
Constructor taking 2D array of complex numbers, width and height.
Parameters:
v - 2D array of complex numbers.
w - Width of image.
h - Height of image.
Method Detail

getColumn

public ComplexNumber[] getColumn(int n)
Takes a column number and returns an array containing the complex numbers in that column.
Parameters:
n - int column number (0 is first column).
Returns:
ComplexNumber array containing column.

putColumn

public void putColumn(int n,
                      ComplexNumber[] c)
Takes a column number and an array of complex numbers and replaces that column with the new data.
Parameters:
n - int column number (0 is first column).
Array - of complex numbers representing the new data.

putRow

public void putRow(int n,
                   ComplexNumber[] c)
Takes a row number and an array of complex numbers and replaces that row with the new data.
Parameters:
n - int row number (0 is first row).
c - Array of complex numbers representing the new data.

getRow

public ComplexNumber[] getRow(int n)
Takes a row number and returns an array containing the complex numbers in that row.
Parameters:
n - int row number (0 is first row).
Returns:
ComplexNumber array containing row.

DCToCentre

public double[][] DCToCentre(double[][] input)
Takes a 2D 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]
Parameters:
input - 2D array of doubles.
Returns:
2D array of doubles representing the new image.

DCToTopLeft

public double[][] DCToTopLeft(double[][] input)
Takes a 2D array of doubles representing an image and translates and wraps the image to put the centre pixel at (0,0).
Parameters:
input - 2D array of doubles.
Returns:
2D array of doubles representing the new image.

DCToTopLeft

public ComplexNumber[][] DCToTopLeft(ComplexNumber[][] input)

DCToCentre

public double[] DCToCentre(double[] input)
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]
Parameters:
input - array of doubles.
Returns:
array of doubles representing the new image.

getReal

public double[] getReal()
Method to extract the real parts from a TwoDArray.
Returns:
An array of doubles representing the real parts of each element of the TwoDArray.

getImaginary

public double[] getImaginary()
Method to extract the imaginary parts from a TwoDArray.
Returns:
An array of doubles representing the imaginary parts of each element of the TwoDArray.

getMagnitude

public double[] getMagnitude()
Method to extract the magnitude of each element from a TwoDArray.
Returns:
An array of doubles representing the magnitude of each element of the TwoDArray.

getPhase

public double[] getPhase()
Method to extract the phase angle of each element from a TwoDArray.
Returns:
An array of doubles representing the phase angle of each element of the TwoDArray.