import ch.psi.pshell.imaging.Filter as Filter
from ch.psi.pshell.imaging.Utils import *
from ch.psi.pshell.imaging.Overlays import *
import ch.psi.pshell.imaging.Pen as Pen

import net.imglib2.script.bufferedimage.BufferedImageImg as BufferedImageImg
import net.imglib2.script.algorithm.FFT as FFT
import net.imglib2.img.display.imagej.ImageJFunctions as ImageJFunctions

bi = None
fftimg = None

class MyFilter(Filter):
    def process(self, image, data):
        #image = rescale(image, 1.0, -20, True)
        image = grayscale(image)
        global bi, fftimg
        bi = image
        im = BufferedImageImg(image)
        fft = FFT(im)
        fftimg = fft
        ret = ImageJFunctions.wrap(fft.image(), "").getBufferedImage()
        return ret

#Setting the filter to a source
tst.setFilter(MyFilter())
tst.initialize()