################################################################################################### 
# Demonstrate creation of an image filters and new source based on filter.
# Also demonstrate creation of image histogram and use of overlays.
################################################################################################### 


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


class MyFilter(Filter):
    def process(self, image, data):
        im = BufferedImageImg(image)
        global last
        image = grayscale(image)        
        i=None
        if last is not None:
            i = sub(image,last, False)
            i = rescale(i,100.0, 0, True)
            i = add(i, last, True)
            i = rescale(i,10.0, 0, True)
        last = image        
        return i

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