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
run("pip")

    
renderer = show_panel(tst)
com_overlay = Crosshairs(Pen(java.awt.Color.WHITE), java.awt.Point(-1,-1), java.awt.Dimension(15,15))
renderer.clearOverlays()
renderer.addOverlays([com_overlay,])

class MyFilter(Filter):
    def process(self, image, data):    
        aux = rescale(image, 1.0, -20, False)        
        ip = ImagePlus("Img", aux)
        stats = get_statistics(ip,Measurements.CENTER_OF_MASS | Measurements.CENTROID )
        (x,y) = (stats.xCenterOfMass,  stats.yCenterOfMass)
        print x,y
        com_overlay.update(java.awt.Point(int(x),int(y)))
        return image

tst.setFilter(MyFilter())    
tst.refresh()
