我用BufferedImage
创建了一个Robot
,并尝试将Rosetta代码中的FFT algorithm应用到Robot
生成的DataBufferInt
上,但实际上失败了方法,我不知道为什么。
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)
我做错了什么?
答案 0 :(得分:1)
您可以使用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());