Package jjil.core

Examples of jjil.core.Complex


                    null,
                    null);
        }
        this.fft.push(im);
        Complex32Image cxmIm = (Complex32Image) this.fft.getFront();
        Complex cxIn[] = cxmIm.getData();
        Complex32Image cxmResult = new Complex32Image(im.getWidth(), im.getHeight());
        Complex cxOut[] = cxmResult.getData();
        Complex cxPsfInv[] = this.cxmPsfInv.getData();
        int nPsfSq[] = this.gPsfSq.getData();
        // compute Wiener filter
        for (int i=0; i<im.getWidth() * im.getHeight(); i++) {
            int nMag = cxIn[i].magnitude();
            int nScale = (nPsfSq[i] * nMag) / ((nPsfSq[i] * nMag) + this.nNoise);
View Full Code Here


        super.setOutput(cxmResult);
    }
   
    private void invertPsf() throws jjil.core.Error {
        this.gPsfSq = new Gray32Image(this.cxmPsfInv.getWidth(), this.cxmPsfInv.getHeight());
        Complex cxPsf[] = this.cxmPsfInv.getData();
        int nData[] = this.gPsfSq.getData();
        for (int i=0; i<this.cxmPsfInv.getWidth() * this.cxmPsfInv.getHeight(); i++) {
            if (Math.abs(cxPsf[i].real()) > MathPlus.SCALE ||
                Math.abs(cxPsf[i].imag()) > MathPlus.SCALE) {
                cxPsf[i] = new Complex(0);
                nData[i] = 1;
            } else {
                int nSq = cxPsf[i].square();
                nData[i] = nSq;
                if (nSq < Gray8WienerDeconv.nThreshold) {
                    // if the square value is too small we will be enhancing noise
                    // too much
                    cxPsf[i] = new Complex(MathPlus.SCALE);
                    nData[i] = 1;
                } else {
                    cxPsf[i] = new Complex(MathPlus.SCALE).div(cxPsf[i]);
                }
            }
        }
    }
View Full Code Here

                            null,
                            null);
        }
        this.fft.push(im);
        Complex32Image cxmIm = (Complex32Image) this.fft.getFront();
        Complex cxIn[] = cxmIm.getData();
        Complex32Image cxmResult = new Complex32Image(im.getWidth(), im.getHeight());
        Complex cxOut[] = cxmResult.getData();
        // compute inverse filter
        int rnCoeff[] = this.rxnCoeffs[this.nStdDev];

        for (int i=0; i<cxmIm.getHeight(); i++) {
            int nRow = i * cxmIm.getWidth();
 
View Full Code Here

        byte data[] = gray.getData();
        // create output
        Complex32Image cxmResult = new Complex32Image(nWidth, nHeight);
        // take FFT of each row
        int nIndex = 0;
        Complex cxRow[] = new Complex[nWidth];
        for (int i=0; i<nHeight; i++) {
            for (int j=0; j<nWidth; j++) {
                // convert each byte to a complex number. Imaginary component is 0.
                // everything gets scaled for accuracy
                cxRow[j] = new Complex((data[nIndex++] - Byte.MIN_VALUE) << SCALE);
            }
            // compute FFT
            Complex cxResult[] = this.fft.fft(cxRow);
            // save result
            System.arraycopy(cxResult, 0, cxmResult.getData(), i*nWidth, nWidth);
        }
        // take FFT of each column
        Complex cxCol[] = new Complex[nHeight];
        for (int j=0; j<nWidth; j++) {
            // copy column into a 1-D array
            for (int i=0; i<nHeight; i++) {
                cxCol[i] = cxmResult.getData()[i*nWidth+j];
            }
            // compute FFT
            Complex cxResult[] = this.fft.fft(cxCol);
            // save result back into column
             for (int i=0; i<nHeight; i++) {
                cxmResult.getData()[i*nWidth+j] = cxResult[i];
            }
       }
View Full Code Here

                      im.toString(),
                      null,
                      null);
        }
        Gray32Image imResult = new Gray32Image(im.getWidth(), im.getHeight());
        Complex cData[] = ((Complex32Image) im).getData();
        int nData[] = imResult.getData();
        for (int i=0; i<im.getWidth()*im.getHeight(); i++) {
            nData[i] = cData[i].magnitude();
        }
        super.setOutput(imResult);
View Full Code Here

    // nLog is the logarithm of the length of x to base 2
    private Complex[] fft(Complex[] x, int nLog) throws jjil.core.Error {
        int N = x.length;

        // base case
        if (N == 1) return new Complex[] { new Complex(x[0]) };

        // fft of even terms
        Complex[] even = new Complex[N/2];
        for (int k = 0; k < N/2; k++) {
            even[k] = new Complex(x[2*k]);
        }
        Complex[] q = fft(even, nLog-1);

        // fft of odd terms
        Complex[] odd  = even;  // reuse the array
        for (int k = 0; k < N/2; k++) {
            odd[k] = new Complex(x[2*k + 1]);
        }
        Complex[] r = fft(odd, nLog-1);

        // combine
        Complex[] y = new Complex[N];
        for (int k = 0; k < N/2; k++) {
            // read complex root of unity from pre-computed array
            Complex wk = new Complex(((Complex [])
                this.cxCoeffs.elementAt(nLog-1))[k]);
            // since we're multiplying two numbers scaled by 2**16 we must divide
            // by 2**16 = 256 * 256, carefully to reduce loss of precision
            Complex cxProd = wk.rsh(8).times(new Complex(r[k]).rsh(8));
            // code below is somewhat strange because complex arithmetic
            // modifies the left argument, always
            y[k] = new Complex(q[k]).plus(cxProd);
            y[k + N/2] = new Complex(q[k]).minus(cxProd);
        }
        return y;
    }
View Full Code Here

        while (nTwoExp <= N) {
            // check to see if we've already filled in the array for this
            // length
            if (cxCoeffs.size() < nLog) {
                // we didn't fill it in, add it now
                Complex cx[] = new Complex[nTwoExp/2];
                for (int k=0; k<nTwoExp/2; k++) {
                    // kth is scaled by 2**16 because of the use of MathPlus.PI
                    int kth = (-2 * k * MathPlus.PI) / nTwoExp;
                    // compute root of unity
                    cx[k] = MathPlus.expImag(kth);
View Full Code Here

                    null,
                    null);
        }
        this.fft.push(im);
        Complex32Image cxmIm = (Complex32Image) this.fft.getFront();
        Complex cxIn[] = cxmIm.getData();
        Complex32Image cxmResult = new Complex32Image(im.getWidth(), im.getHeight());
        Complex cxOut[] = cxmResult.getData();
        Complex cxPsfFft[] = this.cxmPsfInv.getData();
        // compute inverse filter
        for (int i=0; i<im.getWidth() * im.getHeight(); i++) {
            int nMag = cxPsfFft[i].magnitude();
            if (nMag * this.nGamma > MathPlus.SCALE) {
                // cxPsfFft is the FFT of the point spread function, therefore
View Full Code Here

        } else {
            this.fft.setMaxWidth(Math.max(nWidth, nHeight));
        }
         // get access to the complex image
        Complex32Image cxmIn = (Complex32Image) im;
        Complex data[] = cxmIn.getData();
        // create output
        Complex32Image cxmResult = new Complex32Image(nWidth, nHeight);
        // take inverse FFT of each row
        Complex cxRow[] = new Complex[nWidth];
        for (int i=0; i<nHeight; i++) {
            System.arraycopy(data, i*nWidth, cxRow, 0, nWidth);
            // compute inverse FFT
            Complex cxResult[] = this.fft.ifft(cxRow);
            // save result
            System.arraycopy(cxResult, 0, cxmResult.getData(), i*nWidth, nWidth);
        }
        // take inverse FFT of each column
        Complex cxCol[] = new Complex[nHeight];
        for (int j=0; j<nWidth; j++) {
            // copy column into a 1-D array
            for (int i=0; i<nHeight; i++) {
                cxCol[i] = cxmResult.getData()[i*nWidth+j];
            }
            // compute inverse FFT
            Complex cxResult[] = this.fft.ifft(cxCol);
            // save result back into column
             for (int i=0; i<nHeight; i++) {
                cxmResult.getData()[i*nWidth+j] = cxResult[i];
            }
        }
        // convert back to a gray image
        // first convert it to an integer image
        Gray32Image imInteger = new Gray32Image(nWidth, nHeight);
        Complex cxData[] = cxmResult.getData();
        int nData[] = imInteger.getData();
        int nMinVal = Integer.MAX_VALUE;
        int nMaxVal = Integer.MIN_VALUE;
        for (int i = 0; i < nWidth * nHeight; i++) {
            // magnitude is always guaranteed to be >= 0 so we only have to clamp
View Full Code Here

TOP

Related Classes of jjil.core.Complex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.