for i in range (1, timepoints+1):
    IJ.run(imp1, "Select None", "")
    imp1.setT(i)
    # Extact channel to Threshold, set automatic threshold
    imp_threshold= ExtractTimpepointChannel(imp1, 1, i)

    if do_dog_C1:
        imp_DoG = DoG(imp_threshold,1,3)
    else:
        imp_DoG = imp_threshold
    #imp_DoG.show()
    #IJ.run(imp_DoG, "Z Project...", "projection=[Max Intensity] all")
    imp_DoG.setTitle("Difference_of_Gaussian")
    MeanChannel1 = []
    MeanChannel2= []
    maximaC1 = mf.getMaxima(imp_DoG.getProcessor(), noise_C1, True)
    #print maximaC1.npoints
    
    IJ.run(imp1, "Select None", "")
    imp1.setT(i)
    # Extact channel to Threshold, set automatic threshold
    imp_threshold= ExtractTimpepointChannel(imp1, 2, i)

    if do_dog_C2:
        imp_DoG = DoG(imp_threshold,1,3)
    else:
        imp_DoG = imp_threshold
    #imp_DoG.show()
    #IJ.run(imp_DoG, "Z Project...", "projection=[Max Intensity] all")
    imp_DoG.setTitle("Difference_of_Gaussian")
    MeanChannel1 = []
# testMaximumFinder.py
# translated to Jython by J. R. Minter based upon a JavaScript example
# by Wayne Rasband.
# It uses the MaximumFinder.getMaxima() method, which returns the list of x,y
# coordinates as a Polygon.
#  Modifications
#   Date      Who  Ver                       What
# ----------  --- ------  -------------------------------------------------
# 2015-01-23  JRM 0.1.00  Initial translation
# 
from org.python.core import codecs
codecs.setDefaultEncoding('utf-8')

from ij import IJ
from ij.plugin.filter import MaximumFinder

tolerance = 50
excludeOnEdges = False
img = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif")
ip = img.getProcessor()
mf = MaximumFinder()
maxima = mf.getMaxima(ip, tolerance, excludeOnEdges)
print("count = %d" % maxima.npoints)
def get_centroids(imp, tolerance):
    """ Returns maxima using IJ1 """
    mf = MaximumFinder()
    maxima = mf.getMaxima(imp.getProcessor(), tolerance, True)
    return maxima.xpoints, maxima.ypoints, maxima.npoints
findmaximashow = ImagePlus("Found Maxima", maxima)
findmaximashow.show()  # an image of all the points
maximaip = findmaximashow.getProcessor()
maximahist = maximaip.getHistogram()
CountMethod2 = maximahist[255]
print "Using the findMaxima method with a threshold of " + str(
    THRESH) + ", I found " + str(CountMethod2) + " maxima."

IJ.setRawThreshold(findmaximashow, 255, 255, "red")
IJ.run(findmaximashow, "Create Selection", "")
rm.addRoi(findmaximashow.getRoi())
rm.rename(1, "Maxima with threshold")

# ---- METHOD 3-4: API getMaxima WITH THE POINTS COUNTED OR ADDED TO THE RESULTS TABLE

maxima = mf.getMaxima(ip, 100.0, False)
CountMethod3 = maxima.npoints
print "Using the getMaxima method with no threshold , I found " + str(
    CountMethod3) + " maxima."

rt = ResultsTable()
for i in range(maxima.npoints):
    rt.incrementCounter()
    rt.addValue("X", maxima.xpoints[i])
    rt.addValue("Y", maxima.ypoints[i])

rt.show("Results")
CountMethod4 = rt.getCounter()
print "By counting points generated by getMaxima, I found " + str(
    CountMethod4) + " maxima."
# TODO: add these to the ROI mgr