Esempio n. 1
0
	def setUp(self):
		biaflows = BIAFlows('http://biaflows/', '7fe8b526-93ae-481e-932d-e1e0bb598529', '45953ccd-0984-4471-ba68-31c6d212699a')
		IJ.newImage("Ramp", "8-bit ramp", 256, 256, 1)
		imp = IJ.getImage()
		IJ.saveAs("tiff", "./ctest.tif")
		imp.close()

		projects = Projects()
		names = projects.getNames()
		ids = projects.getIDs()
		index = -1
		pid = -1
		try:
			index = names.index('upload-test')
			pid = ids[index]
		except ValueError, e:
			p = Project(name, Ontology('upload-test')).save()
			pid = p.getId()
import sys

from ij import IJ

# Fiji Jython interpreter implements Python 2.5 which does not
# provide support for argparse.
title = sys.argv[-6]
width = int(sys.argv[-5])
height = int(sys.argv[-4])
depth = int(sys.argv[-3])
type = sys.argv[-2].replace('_', ' ')
tmp_image_path = sys.argv[-1]

imp = IJ.newImage(title, type, width, height, depth)
IJ.save(imp, "%s" % tmp_image_path)
Esempio n. 3
0
for i in range(1, n_slicesa + 1):
    imp.setSlice(i)
    n = imp.getProcessor().getPixels()
    n2 = [int(val) for val in n]
    L.append(n2)
imp.changes = False
imp.close()

#get initial dictionary D and construct matrix
imp2 = IJ.getImage()
IJ.run("Enhance Contrast...", "saturated=0 normalize process_all use")
IJ.run("Multiply...", "value=" + str(500) + " stack")
#IJ.run("Add...", "value="+str(10)+" stack")
n_slices = imp2.getStack().getSize()
X = []
for i in range(1, n_slices + 1):
    imp2.setSlice(i)
    n = imp2.getProcessor().getPixels()
    n2 = [val for val in n]
    X.append(n2)

IJ.newImage("Untitled", "RGB white", 512, 512, 1)
IJ.run("Select All")
IJ.setForegroundColor(bc, bc, bc)
IJ.run("Fill", "slice")
imp3 = IJ.getImage()

for i in range(0, len(X[0])):
    IJ.makeRectangle(X[0][i] + 4, X[1][i] + 4, px, px)
    IJ.setForegroundColor(L[0][i], L[1][i], L[2][i])
    IJ.run("Fill", "slice")
Esempio n. 4
0
anno_height = 42  # height of annotation area
anno_width = 800  # width of annotation area (usually image width)
sample_rate = 5  # sample rate (second_per_frame)
um = u'\u03bc' + 'm'
um_px = 125.0 / 370.0  # micron per px, measured in ImageJ
sbar_um = 50  # length of scale bar in micron
sbar_px = round(sbar_um / um_px)  # length of scale bar in px

# Calculate starting time and length for each segment
t_a, t0_a = calcTimestamps(15, 19, 36.0, 346.8, 100.0, sample_rate)
t_b, t0_b = calcTimestamps(15, 28, 16.8, 491.9, 0.0, sample_rate)
t_c, t0_c = calcTimestamps(15, 49, 12.5, 625.4, 0.0, sample_rate)

# Make annotation stack
title = '_2_' + label + '_SPF' + str(sample_rate) + '.tif'
img = IJ.newImage(title, '8-bit black',
                  anno_width, anno_height, t_a + t_b + t_c)

# Add leading texts
labelTextAll(start=0, interval=1, x=10, y=40, fontsize=36,
             text='[Flow:L--->R]')

# Add timestamps for each segment
x_ts, y_ts, fs_ts = 325, 30, 36  # x, y, and font_size
labelTimestamps(start=0, interval=sample_rate,
                x=x_ts, y=y_ts, fontsize=fs_ts,
                range0=1, range1=t_a)
labelTimestamps(start=int(t0_b - t0_a), interval=sample_rate,
                x=x_ts, y=y_ts, fontsize=fs_ts,
                range0=(t_a + 1), range1=(t_a + t_b))
labelTimestamps(start=int(t0_c - t0_a), interval=sample_rate,
                x=x_ts, y=y_ts, fontsize=fs_ts,
Esempio n. 5
0
        filled_positions = pos_dict.keys()
        emptylist = []
        for eachwell in welllist:
            for eachpresuf in presuflist:
                thisprefix, thissuffix = eachpresuf
                for x in range(int(columns)):
                    for y in range(int(rows)):
                        out_name = thisprefix + '_Well_' + eachwell + '_x_' + '%02d' % x + '_y_' + '%02d' % y + '_' + thissuffix
                        if (x, y) in filled_positions:
                            series = pos_dict[(x, y)]
                            in_name = thisprefix + '_Well_' + eachwell + '_Site_' + str(
                                series) + '_' + thissuffix
                            IJ.open(os.path.join(subdir, in_name))
                        else:
                            IJ.newImage("Untitled", "16-bit noise", int(size),
                                        int(size), 1)
                            IJ.run(
                                "Divide...", "value=300"
                            )  #get the noise value below the real camera noise level
                            emptylist.append(out_name)
                        im = IJ.getImage()
                        IJ.saveAs(im, 'tiff', os.path.join(subdir, out_name))
                        IJ.run("Close All")
                        if (x, y) in filled_positions:
                            try:  #try to clean up after yourself, but don't die if you can't
                                os.remove(os.path.join(subdir, in_name))
                            except:
                                pass
                print("Renamed all files for prefix " + thisprefix +
                      " and suffix " + thissuffix + " in well " + eachwell)
            imagelist = os.listdir(subdir)
import sys
from ij import IJ

# Fiji Jython interpreter implements Python 2.5 which does not
# provide support for argparse.
title = sys.argv[ -6 ]
width = int( sys.argv[ -5 ] )
height = int( sys.argv[ -4 ] )
depth = int( sys.argv[ -3 ] )
type = sys.argv[ -2 ].replace( '_', ' ' )
tmp_image_path = sys.argv[ -1 ]

imp = IJ.newImage( title, type, width, height, depth )
IJ.save( imp, "%s" % tmp_image_path )
for f in fileList:
	# get date, sample from filename before opening
	date, sample, style = os.path.basename(f).split(" ") # style is "Montage.tif"
	date = str(date)
	print date +" "+ sample
	r = row_dict[sample[0]]
	c = int(sample[1:])-1
	x = r*660+180
	y = c*320+30
	if currentDate != date:
		print "Found new experiment: " + date
		if expt_imp:
			print "Saving and closing previous experiment."
			IJ.selectWindow(expt_name)
			expt_path = os.path.join(outputDir, expt_name)
			IJ.saveAs("Jpeg", expt_path)
			expt_imp.close()
		currentDate = date
		print "Current date is now " + currentDate
		expt_name = " ".join([currentDate, "Results.jpg"])
		IJ.newImage(expt_name, "8-bit white", 5280, 3885, 1)
		expt_imp = IJ.getImage()
	args = "label=["+sample +"] file=["+ f +"] x="+ str(x) +" y="+ str(y)
	Macro.setOptions(Thread.currentThread(), args)
	IJ.run("place image", args)

IJ.selectWindow(expt_name)
expt_path = os.path.join(outputDir, expt_name)
IJ.saveAs("Jpeg", expt_path)

expt_imp.close()
def particle_analysis(analysis):

    if registration_input == "yes":
        if analysis == "cells":
            for well in wells_list:
                for tile in range(1, tiles):
                    for ext in suffix_list:
                        print("ANALYZING CELL NUMBERS IN WELL {}".format(well))
                        IJ.open("{}/{}_{}_{}_output/{}_{}_{}_{}".format(
                            image_dir, file_prefix, well, tile, file_prefix,
                            well, tile, ext[-22:]))
                        imp = IJ.getImage()
                        IJ.run(
                            "Set Scale...",
                            "distance={} known=1 pixel=1 unit=micrometer global"
                            .format(scale))
                        IJ.run("8-bit")
                        IJ.run("Auto Threshold",
                               "method={}".format(cell_threshold))
                        IJ.run("Watershed")
                        IJ.run(
                            "Analyze Particles...",
                            "size={}-{} micrometer circularity={}-{} show=Nothing display summarize"
                            .format(min_cell_size, max_cell_size,
                                    min_cell_circularity,
                                    max_cell_circularity))
                        IJ.saveAs(
                            "Results",
                            "{}/{}_{}_{}_cells_results/cells_{}_{}_{}_{}.csv".
                            format(image_dir, file_prefix, well, tile,
                                   file_prefix, well, tile, ext[-22:]))
                        IJ.run("Clear Results")
                        if outlines == "yes":
                            IJ.run(
                                "Analyze Particles...",
                                "size={}-{} micrometer circularity={}-{} show=Overlay"
                                .format(min_cell_size, max_cell_size,
                                        min_cell_circularity,
                                        max_cell_circularity))
                            overlay_ = ImagePlus.getOverlay(imp)
                            IJ.newImage("blank_c", "RGB white", 1392, 1040, 1)
                            imp2 = IJ.getImage().setOverlay(overlay_)
                            imp2 = IJ.getImage()
                            imp3 = imp2.flatten()
                            IJ.run(imp3, "8-bit", "")
                            IJ.saveAs(
                                imp3, "Tiff",
                                "{}/{}_{}_{}_cells/outline_cells_{}_{}_{}_{}".
                                format(image_dir, file_prefix, well, tile,
                                       file_prefix, well, tile, ext[-22:]))

        elif analysis == "neurites":
            for well in wells_list:
                for tile in range(1, tiles):
                    for ext in suffix_list:
                        print("ANALYZING NEURITE LENGTHS IN WELL {}".format(
                            well))
                        IJ.open("{}/{}_{}_{}_output/{}_{}_{}_{}".format(
                            image_dir, file_prefix, well, tile, file_prefix,
                            well, tile, ext[-22:]))
                        imp = IJ.getImage()
                        IJ.run(
                            "Set Scale...",
                            "distance={} known=1 pixel=1 unit=micrometer global"
                            .format(scale))
                        IJ.run("8-bit")
                        IJ.run("Auto Threshold",
                               "method={}".format(neurite_threshold))
                        IJ.run("Watershed")
                        IJ.run(
                            "Analyze Particles...",
                            "size={}-{} micrometer circularity={}-{} show=Nothing display summarize"
                            .format(min_neurite_size, max_neurite_size,
                                    min_neurite_circularity,
                                    max_neurite_circularity))
                        IJ.saveAs(
                            "Results",
                            "{}/{}_{}_{}_neurites_results/neurite_{}_{}_{}_{}.csv"
                            .format(image_dir, file_prefix, well, tile,
                                    file_prefix, well, tile, ext[-22:]))
                        IJ.run("Clear Results")
                        if outlines == "yes":
                            IJ.run(
                                "Analyze Particles...",
                                "size={}-{} micrometer circularity={}-{} show=Overlay"
                                .format(min_neurite_size, max_neurite_size,
                                        min_neurite_circularity,
                                        max_neurite_circularity))
                            overlay_ = ImagePlus.getOverlay(imp)
                            IJ.newImage("blank_c", "RGB white", 1392, 1040, 1)
                            imp2 = IJ.getImage().setOverlay(overlay_)
                            imp2 = IJ.getImage()
                            imp3 = imp2.flatten()
                            IJ.run(imp3, "8-bit", "")
                            IJ.saveAs(
                                imp3, "Tiff",
                                "{}/{}_{}_{}_neurites/outline_neurites_{}_{}_{}_{}"
                                .format(image_dir, file_prefix, well, tile,
                                        file_prefix, well, tile, ext[-22:]))

        elif analysis == "branching":
            ic = ImageCalculator()
            for well in wells_list:
                for tile in range(1, tiles):
                    for ext in suffix_list:
                        print("ANALYZING NEURITE BRANCHING IN WELL {}".format(
                            well))
                        img = IJ.open("{}/{}_{}_{}_output/{}_{}_{}_{}".format(
                            image_dir, file_prefix, well, tile, file_prefix,
                            well, tile, ext[-22:]))
                        imp_c = IJ.getImage()
                        imp_n = IJ.getImage()
                        IJ.run(
                            "Set Scale...",
                            "distance={} known=1 pixel=1 unit=micrometer global"
                            .format(scale))
                        IJ.run(imp_c, "8-bit", "")
                        IJ.run(imp_n, "8-bit", "")
                        IJ.run(imp_c, "Auto Threshold",
                               "method={}".format(neurite_threshold))
                        IJ.run(imp_n, "Auto Threshold",
                               "method={}".format(neurite_threshold))
                        IJ.run(imp_c, "Watershed", "")
                        IJ.run(imp_n, "Watershed", "")

                        IJ.run(
                            imp_c, "Analyze Particles...",
                            "size={}-{} micrometer circularity={}-{} show=Overlay"
                            .format(min_cell_size, max_cell_size,
                                    min_cell_circularity,
                                    max_cell_circularity))
                        overlay_c = ImagePlus.getOverlay(imp_c)
                        IJ.run(
                            imp_n, "Analyze Particles...",
                            "size={}-{} micrometer circularity={}-{} show=Overlay"
                            .format(min_neurite_size, max_neurite_size,
                                    min_neurite_circularity,
                                    max_neurite_circularity))
                        overlay_n = ImagePlus.getOverlay(imp_n)
                        IJ.newImage("blank_c", "RGB white", 1392, 1040, 1)
                        imp_c2 = IJ.getImage().setOverlay(overlay_c)
                        imp_c2 = IJ.getImage()
                        imp_c3 = imp_c2.flatten()
                        IJ.run(imp_c3, "8-bit", "")
                        IJ.run(imp_c3, "Make Binary", "")

                        IJ.newImage("blank_n", "RGB white", 1392, 1040, 1)
                        imp_n2 = IJ.getImage().setOverlay(overlay_n)
                        imp_n2 = IJ.getImage()
                        imp_n3 = imp_n2.flatten()
                        IJ.run(imp_n3, "8-bit", "")
                        IJ.run(imp_n3, "Make Binary", "")
                        IJ.run(imp_n3, "Find Edges", "")

                        imp_res = ic.run("Multiply create", imp_n3, imp_c3)
                        IJ.run("Clear Results")

                        if outlines == "yes":
                            IJ.saveAs(
                                imp_res, "Tiff",
                                "{}/{}_{}_{}_branching/branching_{}_{}_{}_{}".
                                format(image_dir, file_prefix, well, tile,
                                       file_prefix, well, tile, ext[-22:]))
                        IJ.run(
                            imp_res, "Analyze Particles...",
                            "size=0-infinity micrometer circularity=0.00-1.00 show=Nothing display summarize"
                        )
                        IJ.saveAs(
                            "Results",
                            "{}/{}_{}_{}_branching_results/branching_{}_{}_{}_{}.csv"
                            .format(image_dir, file_prefix, well, tile,
                                    file_prefix, well, tile, ext[-22:]))
                        IJ.run("Clear Results")
    else:
        if analysis == "cells":
            for well in wells_list:
                for tile in range(1, tiles):
                    for ext in suffix_list:
                        print("ANALYZING CELL NUMBERS IN WELL {}".format(well))
                        IJ.open("{}/{}_{}_{}/{}_{}_{}_{}".format(
                            image_dir, file_prefix, well, tile, file_prefix,
                            well, tile, ext[-22:]))
                        imp = IJ.getImage()
                        IJ.run(
                            "Set Scale...",
                            "distance={} known=1 pixel=1 unit=micrometer global"
                            .format(scale))
                        IJ.run("8-bit")
                        IJ.run("Auto Threshold",
                               "method={}".format(cell_threshold))
                        IJ.run("Watershed")
                        IJ.run(
                            "Analyze Particles...",
                            "size={}-{} micrometer circularity={}-{} show=Nothing display summarize"
                            .format(min_cell_size, max_cell_size,
                                    min_cell_circularity,
                                    max_cell_circularity))
                        IJ.saveAs(
                            "Results",
                            "{}/{}_{}_{}_cells_results/cells_{}_{}_{}_{}.csv".
                            format(image_dir, file_prefix, well, tile,
                                   file_prefix, well, tile, ext[-22:]))
                        IJ.run("Clear Results")
                        if outlines == "yes":
                            IJ.run(
                                "Analyze Particles...",
                                "size={}-{} micrometer circularity={}-{} show=Overlay"
                                .format(min_cell_size, max_cell_size,
                                        min_cell_circularity,
                                        max_cell_circularity))
                            overlay_ = ImagePlus.getOverlay(imp)
                            IJ.newImage("blank_c", "RGB white", 1392, 1040, 1)
                            imp2 = IJ.getImage().setOverlay(overlay_)
                            imp2 = IJ.getImage()
                            imp3 = imp2.flatten()
                            IJ.run(imp3, "8-bit", "")
                            IJ.saveAs(
                                imp3, "Tiff",
                                "{}/{}_{}_{}_cells/outline_cells_{}_{}_{}_{}".
                                format(image_dir, file_prefix, well, tile,
                                       file_prefix, well, tile, ext[-22:]))

        elif analysis == "neurites":
            for well in wells_list:
                for tile in range(1, tiles):
                    for ext in suffix_list:
                        print("ANALYZING NEURITE LENGTHS IN WELL {}".format(
                            well))
                        IJ.open("{}/{}_{}_{}/{}_{}_{}_{}".format(
                            image_dir, file_prefix, well, tile, file_prefix,
                            well, tile, ext[-22:]))
                        imp = IJ.getImage()
                        IJ.run(
                            "Set Scale...",
                            "distance={} known=1 pixel=1 unit=micrometer global"
                            .format(scale))
                        IJ.run("8-bit")
                        IJ.run("Auto Threshold",
                               "method={}".format(neurite_threshold))
                        IJ.run("Watershed")
                        IJ.run(
                            "Analyze Particles...",
                            "size={}-{} micrometer circularity={}-{} show=Nothing display summarize"
                            .format(min_neurite_size, max_neurite_size,
                                    min_neurite_circularity,
                                    max_neurite_circularity))
                        IJ.saveAs(
                            "Results",
                            "{}/{}_{}_{}_neurites_results/neurite_{}_{}_{}_{}.csv"
                            .format(image_dir, file_prefix, well, tile,
                                    file_prefix, well, tile, ext[-22:]))
                        IJ.run("Clear Results")
                        if outlines == "yes":
                            IJ.run(
                                "Analyze Particles...",
                                "size={}-{} micrometer circularity={}-{} show=Overlay"
                                .format(min_neurite_size, max_neurite_size,
                                        min_neurite_circularity,
                                        max_neurite_circularity))
                            overlay_ = ImagePlus.getOverlay(imp)
                            IJ.newImage("blank_c", "RGB white", 1392, 1040, 1)
                            imp2 = IJ.getImage().setOverlay(overlay_)
                            imp2 = IJ.getImage()
                            imp3 = imp2.flatten()
                            IJ.run(imp3, "8-bit", "")
                            IJ.saveAs(
                                imp3, "Tiff",
                                "{}/{}_{}_{}_neurites/outline_neurites_{}_{}_{}_{}"
                                .format(image_dir, file_prefix, well, tile,
                                        file_prefix, well, tile, ext[-22:]))

        elif analysis == "branching":
            ic = ImageCalculator()
            for well in wells_list:
                for tile in range(1, tiles):
                    for ext in suffix_list:
                        print("ANALYZING NEURITE BRANCHING IN WELL {}".format(
                            well))
                        img = IJ.open("{}/{}_{}_{}/{}_{}_{}_{}".format(
                            image_dir, file_prefix, well, tile, file_prefix,
                            well, tile, ext[-22:]))
                        imp_c = IJ.getImage()
                        imp_n = IJ.getImage()
                        IJ.run(
                            "Set Scale...",
                            "distance={} known=1 pixel=1 unit=micrometer global"
                            .format(scale))
                        IJ.run(imp_c, "8-bit", "")
                        IJ.run(imp_n, "8-bit", "")
                        IJ.run(imp_c, "Auto Threshold",
                               "method={}".format(neurite_threshold))
                        IJ.run(imp_n, "Auto Threshold",
                               "method={}".format(neurite_threshold))
                        IJ.run(imp_c, "Watershed", "")
                        IJ.run(imp_n, "Watershed", "")

                        IJ.run(
                            imp_c, "Analyze Particles...",
                            "size={}-{} micrometer circularity={}-{} show=Overlay"
                            .format(min_cell_size, max_cell_size,
                                    min_cell_circularity,
                                    max_cell_circularity))
                        overlay_c = ImagePlus.getOverlay(imp_c)
                        IJ.run(
                            imp_n, "Analyze Particles...",
                            "size={}-{} micrometer circularity={}-{} show=Overlay"
                            .format(min_neurite_size, max_neurite_size,
                                    min_neurite_circularity,
                                    max_neurite_circularity))
                        overlay_n = ImagePlus.getOverlay(imp_n)
                        IJ.newImage("blank_c", "RGB white", 1392, 1040, 1)
                        imp_c2 = IJ.getImage().setOverlay(overlay_c)
                        imp_c2 = IJ.getImage()
                        imp_c3 = imp_c2.flatten()
                        IJ.run(imp_c3, "8-bit", "")
                        IJ.run(imp_c3, "Make Binary", "")

                        IJ.newImage("blank_n", "RGB white", 1392, 1040, 1)
                        imp_n2 = IJ.getImage().setOverlay(overlay_n)
                        imp_n2 = IJ.getImage()
                        imp_n3 = imp_n2.flatten()
                        IJ.run(imp_n3, "8-bit", "")
                        IJ.run(imp_n3, "Make Binary", "")
                        IJ.run(imp_n3, "Find Edges", "")

                        imp_res = ic.run("Multiply create", imp_n3, imp_c3)
                        IJ.run("Clear Results")

                        if outlines == "yes":
                            IJ.saveAs(
                                imp_res, "Tiff",
                                "{}/{}_{}_{}_branching/branching_{}_{}_{}_{}".
                                format(image_dir, file_prefix, well, tile,
                                       file_prefix, well, tile, ext[-22:]))
                        IJ.run(
                            imp_res, "Analyze Particles...",
                            "size=0-infinity micrometer circularity=0.00-1.00 show=Nothing display summarize"
                        )
                        IJ.saveAs(
                            "Results",
                            "{}/{}_{}_{}_branching_results/branching_{}_{}_{}_{}.csv"
                            .format(image_dir, file_prefix, well, tile,
                                    file_prefix, well, tile, ext[-22:]))
                        IJ.run("Clear Results")