Примените FFT на BufferedImage, дайте мне ArrayIndexOutOfBoundsException - PullRequest
0 голосов
/ 30 ноября 2018

Я создаю BufferedImage с Robot и пытаюсь применить алгоритм FFT из кода розетки на DataBufferInt сгенерированный Robot, но он не работает в методе 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)

Я что-то не так делаю?

1 Ответ

0 голосов
/ 07 декабря 2018

Вы можете использовать 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());
...