sel15 0 Newbie Poster

I have implemented an FFT algorithm (by looking it up online) and integrated it into ImageJ but when I run it the image produced by the FFT algorithm is different from the image produced by the ImageJ software. I can't seem to find the error, I was hoping someone can tell me where I am going wrong.

Here is where I call my fft algorithm:

private int widthSize;
private int largeNum;
double [] cos;
double [] sine;
float [] finalArray;

public void fftTransform(int w){
    //check if the matrix is of size of power of 2. If not then display an error. 
    this.widthSize = w;
    largeNum = (int)(Math.log(widthSize) / Math.log(2));    //if width=256, then temp =8

    if(widthSize != (1<<largeNum))  // "<<" signed left shift operator so it creates the number 256, and checks if the width is 256 or not (because it is a power of 2).
        throw new IllegalArgumentException("Image is not a power of 2, fix width and height size of matrix");

    //Make lookup tables, you have to compute this if the size changes. 
    computeCosSineTable(widthSize);

    //get the data of the original image (pixel data).
    float[] fft = (float[])getPixels();

    System.out.println("This is the fft new:  ");
    for(int i=0; i<fft.length; i++){
        System.out.println(fft[i]);
    }

    float[] real = new float[widthSize*widthSize];
    float[] imag = new float[widthSize*widthSize];
    for (int i=0; i<widthSize; i++) {
        FHTreal(i, widthSize, fft, real);
        FHTimag(i, widthSize, fft, imag);
    }

    finalArray = four1(fdata, fdata.length/4,1);
   // fft2(real,imag);
    //do2DFFT(real,imag);
    isFrequencyDomain = !false;
    System.out.println(finalArray.length);
}

And this is the algorithm (FFT):

public float[] four1(float data[], int nn, int isign) {

          int i, j, n, mmax, m, istep;
          float wtemp, wr, wpr, wpi, wi, theta, tempr, tempi;

          n = nn << 1;
          j = 1;
          for(i = 1; i < n; i += 2) {
            if(j > i) {
              float temp;
              temp = data[j];
              data[j] = data[i];
              data[i] = temp;
              temp = data[j+1];
              data[j+1] = data[i+1];
              data[i+1] = temp;
            }
            m = n >> 1;
            while(m >= 2 && j > m) {
              j -= m;
              m >>= 1;
            }
            j += m;
          }
          mmax = 2;
          while(n > mmax) {
            istep = (mmax << 1);
            theta = (float) (isign*(6.28318530717959/mmax));
            wtemp = (float) Math.sin(0.5*theta);
            wpr = (float) (-2.0*wtemp*wtemp);
            wpi = (float) Math.sin(theta);
            wr = (float) 1.0;
            wi = (float) 0.0;
            for(m = 1; m < mmax; m += 2) {
              for(i = m; i <= n; i += istep) {
                j = i+mmax;
                tempr = wr*data[j]-wi*data[j+1];
                tempi = wr*data[j+1]+wi*data[j];
                data[j] = data[i] - tempr;
                data[j+1] = data[i+1] - tempi;
                data[i] += tempr;
                data[i+1] += tempi;
              }
            wr = (wtemp=wr)*wpr-wi*wpi+wr;
            wi = wi*wpr+wtemp*wpi+wi;
            }
            mmax = istep;
          }
          return data;
        }

I have tried a couple fft algorithms from the internet but I can't seem to get it work. I have also made my own as well but that is way off. You can see the pictures here as well:
http://stackoverflow.com/questions/24291896/fft-image-is-not-the-same-as-the-fft-image-produced-in-imagej