def analyzeTUB():

    rm = RoiManager().getInstance()

    #Set imageJ preference meassurements to "area"
    IJ.run("Set Measurements...", "area display redirect=None decimal=3")

    #Variable used for iteration
    counter = 0

    #Clear previous resuslts
    IJ.run("Clear Results")

    # Make library, to be iterated through. Room for improvement
    lis_dic = [{'path': sub[i]} for i in range(len(sub))]
    if not lis_dic:
        sys.exit('Did you check the right box?')

    # Calculate area of channel #1 (Calculation requires that area is chosen as measured value)
    for i in lis_dic:
        print i
        for p in data[counter][::-1]:
            print p
            if '_' + channel1 + '_' in p:
                imp1 = IJ.openImage(i['path'] + '/' + p)
                IJ.setThreshold(imp1, lowth1, 255)
                IJ.run(imp1, "Create Selection", "")
                roi = rm.getRoi(imp1)
                #rm.runCommand(imp1, 'Add')
                IJ.run(imp1, "Measure", "")

            if '_' + channel2 + '_' in p:
                imp2 = IJ.openImage(i['path'] + '/' + p)
                IJ.setThreshold(imp2, lowth2, 255)
                rm.runCommand(imp1, 'Select')
                IJ.run(imp2, "Analyze Particles...", "size=0-4000 summarize")

        counter += 1

    # Reset counter
    counter = 0

    IJ.renameResults(channel2)
def analyzeDAPI():

    #Set imageJ preference meassurements to "area"
    IJ.run("Set Measurements...", "area display redirect=None decimal=3")

    #Variable used for iteration
    counter = 0

    #Clear previous resuslts
    IJ.run("Clear Results")

    # Make library, to be iterated through. Room for improvement
    lis_dic = [{'path': sub[i]} for i in range(len(sub))]
    if not lis_dic:
        sys.exit('Did you check the right box?')

    # Calculate number of particles in channel #1 (Calculation requires that DAPI is chosen as measured value)
    for i in lis_dic:
        for p in data[counter]:
            if '_' + channel1 + '_' in p:
                imp1 = IJ.openImage(i['path'] + '/' + p)
                IJ.setThreshold(imp1, lowth1, 255)
                IJ.run(imp1, "Convert to Mask", "")
                IJ.run(imp1, "Watershed", "")
                IJ.run(imp1, "Analyze Particles...",
                       "size=200-3000 pixel summarize")

        counter += 1
    IJ.renameResults(channel1)

    # Reset counter
    counter = 0

    # Calculate area of channel #2
    for i in lis_dic:
        for p in data[counter]:
            if '_' + channel2 + '_' in p:
                imp2 = IJ.openImage(i['path'] + '/' + p)
                IJ.setThreshold(imp2, lowth2, 255)
                IJ.run(imp2, "Create Selection", "")
                IJ.run(imp2, "Measure", "")
        counter += 1
    IJ.renameResults(channel2)
    for jj in range(0, 65536):
        ii += hist[jj]
        if ii > histsum / 2:
            break
    return jj


gd = GenericDialog("Image Information")
gd.addNumericField("Cardiomyocye Stain Channel Number", 1, 0, 10, "")
gd.addNumericField("Nuclear Stain Channel Number", 2, 0, 10, "")
gd.showDialog()
cmChan = int(gd.getNextNumber())
nucChan = int(gd.getNextNumber())
IJ.setProperty("cmChan", cmChan)
IJ.setProperty("nucChan", nucChan)

analyte = WindowManager.getCurrentImage()
title = analyte.getTitle()
IJ.run("Split Channels")
nucTitle = "C{}-{}".format(nucChan, title)
nucIp = WindowManager.getImage(nucTitle)
nucIpMedian = calcMedian(nucIp)
IJ.run(nucIp, "Subtract...", "value=" + str(nucIpMedian) + " stack")
IJ.run("Merge Channels...",
       "c1=[C1-{}] c2=[C2-{}] create".format(title, title))
cmt = ResultsTable()
cmt.show("Cardiomyocyte Results")
IJ.renameResults("Cardiomyocyte Results")
nuct = ResultsTable()
nuct.show("Nucleus Results")
IJ.renameResults("Nucleus Results")