Using PyImageJ to get the FFT

Hello! I’ve been trying to drum up a simple script in python that calls pyimagej take an image as input, and return the Fourier transform of that image. Ideally I would be able to do further operations on the image, such as using numpy operations on it.

I’ve tried to do it using the ops, as outlined in the tutorial:

import imagej
from skimage import io
import numpy as np

ij = imagej.init('sc.fiji:fiji:2.0.0-pre-10')
img = io.imread('/path/to/my/image')
img = np.mean(img, axis=2)


## I've also tried the form below
# ij.op().run("filter.fft",

But I just got the original image back instead. I also tried the following

result = np.zeros(img.shape)

But I just got a black image instead. I tried taking the RandomAccessibleInterval output of the filter function and converting it back to a numpy array:

output = ij.op().run("filter.fft",

but I got the following error:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/suliat16/reference/pycharm-community-2018.3.2/helpers/pydev/_pydev_bundle/", line 198, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/home/suliat16/reference/pycharm-community-2018.3.2/helpers/pydev/_pydev_imps/", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/suliat16/nint/", line 31, in <module>
  File "/home/suliat16/reference/miniconda3/envs/nint/lib/python3.7/site-packages/imagej/", line 225, in from_java
    return self.rai_to_numpy(rai)
  File "/home/suliat16/reference/miniconda3/envs/nint/lib/python3.7/site-packages/imagej/", line 152, in rai_to_numpy
    self._ij.op().run("copy.rai", self.to_java(result), rai)
  File "jnius/jnius_export_class.pxi", line 1044, in jnius.JavaMultipleMethod.__call__
  File "jnius/jnius_export_class.pxi", line 766, in jnius.JavaMethod.__call__
  File "jnius/jnius_export_class.pxi", line 843, in jnius.JavaMethod.call_method
  File "jnius/jnius_utils.pxi", line 91, in jnius.check_exception
jnius.JavaException: JVM exception occurred: java.util.concurrent.ExecutionException: java.lang.ClassCastException: class net.imglib2.type.numeric.complex.ComplexFloatType cannot be cast to class net.imglib2.type.numeric.real.AbstractRealType (net.imglib2.type.numeric.complex.ComplexFloatType and net.imglib2.type.numeric.real.AbstractRealType are in unnamed module of loader 'app')

I tried to access the FFT.forward() function, but I dont know how to access it through python. Both

from jnius import autoclass
FFT = autoclass('ij.IJ.FFT')
FFT = autoclass('ij.FFT')
FFT = autoclass('ij.plugin.filter.FFT')

returned some version of

  File "jnius/jnius_export_func.pxi", line 26, in jnius.find_javaclass
jnius.JavaException: Class not found b'ij/IJ/FFT'

At this point I really don’t know what to do. Sorry if this question is redundant or long-winded, but I’m really stumped here.

Just curious why you would want to send your numpy array from python to Java and perform the FFT in ImageJ when there are perfectly good FFT implementations that work directly on numpy arrays?
As you are already importing skimage have a look here:
You can also get GPU-accelerated fft using for example reikna or more conveniently gputools (

I didn’t realize that was an option- I’m rather new to image processing, and I was trying to figure out what can be done in python using pyimagej and what can’t. I hadn’t realized that there were other options!

Algum sabe como imprimir em view uma RandomAcessibleIntevale Complexa?