在 BufferedImage 上应用 FFT 给我一个 ArrayIndexOutOfBoundsException

Apply FFT on BufferedImage give me an ArrayIndexOutOfBoundsException

我创建了一个由 Robot 生成的 BufferedImage with Robot and try to apply FFT algorithm from rosetta code on the DataBufferInt,但它在 fft 方法中失败了,我不知道为什么。

Robot r = new Robot();
Rectangle rect = new Rectangle(10,10,200,200);
BufferedImage capture = r.createScreenCapture(rect);
// All data in getDataBuffer() seems to be negative
int[] pixels = ((DataBufferInt)buffer.getRaster().getDataBuffer()).getData();
Complex[] cinput = new Complex[pixels.length];
for (int i = 0; i < pixels.length; i++) {
    cinput[i] = new Complex(pixels[i], 0.0);
}
// Fail (method from rosetta code)
FastFourierTransform.fft(cinput);

给我:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 40000
at engine.FastFourierTransform.fft(FastFourierTransform.java:42)
at engine.ImageProcessing.FFT(ImageProcessing.java:30)
at test.Testor.main(Testor.java:24)

我做错了什么?

您可以使用Catalano Framework,您可以轻松地进行快速傅里叶变换。也适用于 MxN 大小的图像。

Robot r = new Robot();
Rectangle rect = new Rectangle(10,10,200,200);
BufferedImage capture = r.createScreenCapture(rect);

FastBitmap fb = new FastBitmap(capture);
fb.toGrayscale();

FourierTransform ft = new FourierTransform(fb);
ft.Forward();
fb = ft.toFastBitmap();

//Display the image
JOptionPane.showMessageDialog(null, fb.toIcon());