ImageJ图像上的矩形部分不执行FFT

时间:2014-07-29 22:18:38

标签: java fft imagej

所以我建立了自己的FFT算法,除了ImageJ之外,它在图像上进行FFT,但是当我选择图像的某个区域(使用矩形选择工具)时,它不会进行FFT。如果选择大小是2的幂(如选择高度和宽度假设为128),则对其进行FFT。无论选择大小如何,我都希望完成FFT。所以我想将数组大小增加到2的幂并填充它,但我不知道增加它的大小以及填充它的内容。任何帮助,将不胜感激。

这是我的代码(它检查图像宽度,高度的大小,然后获取像素)。此函数驻留在FHT类中:

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; 
}

1 个答案:

答案 0 :(得分:1)

如何在任意尺寸的输入上使用base-2傅立叶变换例程的基本问题是actually answered on Math.SE。如果你想要精确非幂2的DFT结果,它就不像填充和截断那么简单。