简体   繁体   中英

Rectangular section on ImageJ image does not do FFT

So I built my own FFT algorithm apart from the ImageJ one and it does the FFT on the image but when I select a certain region of the image (using the rectangle selection tool) it doesn't do the FFT. If the selection size is a power of 2 (like selection height and width are suppose 128) it does the FFT on it. I want the FFT to be done regardless of the selection size. So I want to increase the array size to be a power of two and populate it but I don't know what size to increase it to and what to populate it with. Any help would be appreciated.

This is my code (it checks the size of image width, height and then gets the pixels). This function resides in the FHT class:

public void fftTransform(int w){
    maxN = 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).
        String message = "The image size is not a power of 2. Please change image size in Image -> resize";
        JOptionPane.showMessageDialog(new JFrame(), message, "Error in overlapping images",JOptionPane.ERROR_MESSAGE);
        throw new IllegalArgumentException("Image is not a power of 2, fix width and height size of matrix");
    }

    //get the data of the original image (pixel data).
    float[] fht = (float[])getPixels();     //fht is variable that maybe inherited and the name cannot change or the program will not work
    Transform3D transform = new Transform3D(fht);

    ComputeClassicalFFT myFFT = new ComputeClassicalFFT();
    finalArray = myFFT.fft(fht, false);
    isFrequencyDomain = !false; 
}

The underlying question, how to use a base-2 Fourier transform routine on arbitrarily dimensioned input, was actually answered on Math.SE . It's not as simple as padding and truncating if you want the precise non-power-of-2 DFT result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM