Ejemplo n.º 1
0
def run_stitch(filePath):
	basePath,baseName = os.path.split(filePath)
	imagePrefix = os.path.splitext(baseName)[0]
	resizeName = basePath + "/" + baseName + "_tiles/resized/"
	checkName = basePath + "/" + baseName + "_tiles/resized/" + imagePrefix + "_seq/"
	activeName = basePath + "/" + baseName + "_tiles"
	IJ.log("Stitching " + filePath + "...")
	if (not os.path.isdir(checkName)):
		thread = Thread.currentThread()
		originalThread = thread.getName()
		thread.setName("Run$_stitch_process")
		options = "choose=" + resizeName + " select=" + activeName + "/tile_info.txt image_prefix=" + imagePrefix
		Macro.setOptions(Thread.currentThread(),options)
		try:
			IJ.run("Stitch wrapper",options)
			IJ.log("succeeded")
			returnVal = 0
		except:
			IJ.log("failed")
			os.rmdir(checkName)
			returnVal = 1
		thread.setName(originalThread)
		Macro.setOptions(thread,None)
	else:
		IJ.log("skipped")
		returnVal = 2

	return returnVal
Ejemplo n.º 2
0
def findclearcell(inDir, currentDir, fileName):
  print "Opening", fileName
  file_path= os.path.join(currentDir, fileName)
  options = ImporterOptions()
  options.setId(file_path)
  options.setSplitChannels(True)
  imps = BF.openImagePlus(options)
  for imp in imps:
  	imp.show()
  if not imps:
  	return
  IJ.selectWindow(fileName + " - C=2")
  IJ.run("Close")
  IJ.selectWindow(fileName + " - C=1")
  IJ.run("Close")
  IJ.selectWindow(fileName + " - C=0")
  IJ.run("Close")
  IJ.selectWindow(fileName + " - C=3")
  IJ.run("8-bit")
  IJ.run("Options...", "iterations=1 count=1 black edm=8-bit")
  IJ.setThreshold(62, 255)
  IJ.run("Convert to Mask", "method=Default backgorund=Dark black")
  Macro.setOptions("Stack position")
  for n in range(4,15):
	n+=1
	IJ.setSlice(n)
	IJ.run(imp, "Analyze Particles...", "size=7.2-9 circularity=0.7-0.95 display")
Ejemplo n.º 3
0
def run_resize(filePath):
	basePath,baseName = os.path.split(filePath)
	checkName = basePath + "/" + baseName + "_tiles/resized/"
	activeName = basePath + "/" + baseName + "_tiles"
	IJ.log("Resizing " + filePath + "...")
	if (not os.path.isdir(checkName)):
		thread = Thread.currentThread()
		originalThread = thread.getName()
		thread.setName("Run$_resize_process")
		totFileSize = get_directory_size(activeName) / 1048576.0
		totFijiMem = Memory().maxMemory() / 1048576.0 
		IJ.run("Bio-Formats Importer", "open=["+ activeName +"/tile_1.ome.tif] color_mode=Default view=Hyperstack stack_order=XYCZT");
		tileImage = WindowManager.getImage("tile_1.ome.tif")
		nChannels = tileImage.getNChannels()
		tileImage.close()
		allowedMem = min(nChannels * totFijiMem/10.0, totFijiMem/3.0)
		ratio = allowedMem / totFileSize
		if (ratio < 1):
			options = "choose=" + activeName + " sizing_ratio=" + str(ratio)
		else:
			options = "choose=" + activeName + " sizing_ratio=1.00"
		Macro.setOptions(Thread.currentThread(),options)
		try:
			IJ.run("Batch resizer",options)
			IJ.log("succeeded with sizing ratio=" + str(ratio))
			returnVal = 0
		except:
			IJ.log("failed")
			returnVal = 1
		thread.setName(originalThread)
		Macro.setOptions(thread,None)
	else:
		IJ.log("skipped")
		returnVal = 2

	return returnVal
Ejemplo n.º 4
0
def run_explode(filePath):
	basePath,baseName = os.path.split(filePath)
	checkName = basePath + "/" + baseName + "_tiles"
	IJ.log("Exploding " + filePath + "...")
	if (not os.path.isdir(checkName)):
		thread = Thread.currentThread()
		originalThread = thread.getName()
		thread.setName("Run$_explode_process")
		options = "open=" + filePath
		Macro.setOptions(Thread.currentThread(),options)
		try:
			IJ.run("Explode Into Tiles",options)
			IJ.log("succeeded")
			returnVal = 0
		except:
			IJ.log("failed")
			returnVal = 1
		thread.setName(originalThread)
		Macro.setOptions(thread,None)
	else:
		IJ.log("skipped")
		returnVal = 2

	return returnVal
Ejemplo n.º 5
0
BinarizeChromosome(impch1)
impch1.show()

ic = ImageCalculator()
#TODO
imp = ic.run("Multiply create stack", impch1, impch2);
imp.show()


IJ.run(imp, "Background Subtractor", "length=10 stack")
#options = "radius=3 cutoff=1 percentile=0.01"
options = "radius=%d cutoff=%d percentile=%f" % (radius, cutoff, percentile)
thread = thr.currentThread()
original_name = thread.getName()
thread.setName("Run$_my_batch_process")
Macro.setOptions(thr.currentThread(), options)
pt = IJ.runPlugIn(imp, "de.embl.cmci.pt3d.Dot_Detector_3D", "")

impdimA = imp.getDimensions()
ims = imp.createEmptyStack()
for i in range(impdimA[3]): 
	ims.addSlice(None, ByteProcessor(impdimA[0], impdimA[1]))
imp2 = ImagePlus("test", ims)

nSlices = imp2.getNSlices()

rt = ResultsTable.getResultsTable()
xindex = rt.getColumnIndex("x")
yindex = rt.getColumnIndex("y") 
zindex = rt.getColumnIndex("z")
xA = rt.getColumn(xindex)
Ejemplo n.º 6
0
from ij import IJ, Macro
import java.lang.Thread as Thread
# from ij.gui import WaitForUserDialog
import glob, os

__author__ = 'Nichole Wespe'

inputDir = IJ.getDirectory("Choose Source Directory ")
outputDir = IJ.getDirectory("Choose Destination Directory ")
pattern = os.path.join(inputDir, "*Start.jpg")
fileList = glob.glob(pattern)
print "Found " + str(len(fileList)) + " sample files to montage."

subDir = os.path.join(outputDir, "Montages")
if not os.path.exists(subDir):
    os.mkdir(subDir)

for f in fileList: # get date, sample from filename before opening
    date, sample, time = os.path.basename(f).split(" ")
    # find matching End.tif file
    f2 = os.path.join(inputDir, str(date) +" "+ str(sample) +" End.jpg")
    montage_name = " ".join([date, sample, "Montage.jpg"])
    path = os.path.join(subDir, montage_name)
    args = "sample=["+montage_name +"] file1=["+ f +"] file2=["+ f2 +"] path=["+ path +"]"
    Macro.setOptions(Thread.currentThread(), args)
    IJ.run("create horiz montage", args)
Ejemplo n.º 7
0
def main():

    # Get active dataset
    #img = IJ.getImage()
    display = displayservice.getActiveDisplay()
    active_dataset = imagedisplayservice.getActiveDataset(display)

    if not active_dataset:
        IJ.showMessage('No image opened.')
        return

    # Get image path
    fname = active_dataset.getSource()
    dir_path = os.path.dirname(fname)

    if not fname:
        IJ.showMessage('Source image needs to match a file on the system.')
        return

    # Open ROIs
    rois = RoiManager.getInstance()
    if not rois:
        roi_path = os.path.join(dir_path, "RoiSet.zip")
        if not os.path.isfile(roi_path):
            try:
                roi_path = glob.glob(os.path.join(dir_path, "*.roi"))[0]
            except:
                roi_path = None

        if not roi_path:
            IJ.showMessage('No ROIs. Please use Analyze > Tools > ROI Manager...')
            return

        rois = RoiManager(True)
        rois.reset()
        rois.runCommand("Open", roi_path)

    IJ.log('Image filename is %s' % fname)
    dt = get_dt(active_dataset)

    rois_array = rois.getRoisAsArray()
    for i, roi in enumerate(rois_array):

        crop_id = i + 1
        IJ.log("Croping %i / %i" % (crop_id, len(rois_array)))

        # Get filename and basename of the current cropped image
        crop_basename = "crop%i_%s" % (crop_id, active_dataset.getName())
        crop_basename = os.path.splitext(crop_basename)[0] + ".ome.tif"
        crop_fname = os.path.join(os.path.dirname(fname), crop_basename)

        # Get bounds and crop
        bounds = roi.getBounds()
        dataset = crop(ij, datasetservice, active_dataset,
                       bounds.x, bounds.y, bounds.width,
                       bounds.height, crop_basename)

        # Show cropped image
        ij.ui().show(dataset.getName(), dataset)

        # Save cropped image (ugly hack)
        IJ.log("Saving crop to %s" % crop_fname)

        imp = IJ.getImage()
        bfExporter = LociExporter()
        macroOpts = "save=[" + crop_fname + "]"
        bfExporter.setup(None, imp)
        Macro.setOptions(macroOpts)
        bfExporter.run(None)

        imp.close()

    IJ.log('Done')
Ejemplo n.º 8
0
# ----------  --- ------  -------------------------------------------------
# 2014-10-15  JRM 0.1.00  Get'er done

from org.python.core import codecs
codecs.setDefaultEncoding('utf-8')

from ij import IJ
from ij import Macro
from java.lang import Thread

# Prepare options for Bandpass filter
options = "filter_large=40 filter_small=3 suppress=None tolerance=5 autoscale saturate"
# Get the current thread
thread = Thread.currentThread()
original_name = thread.getName()
# Rename current thread
thread.setName("Run$_my_batch_process")
# Set the options for the current thread
Macro.setOptions(Thread.currentThread(), options)

# Get the current image
imp = IJ.getImage();
# Finally, run the bandpass filter without dialogs:
IJ.runPlugIn(imp, "ij.plugin.filter.FFTFilter", "")

# Be nice: undo naming, so other scripts may run with dialogs
thread.setName(original_name);
# Be safe: remove the thread's options from the table
# (which also removes the reference to the thread itself)
Macro.setOptions(thread, None)
Ejemplo n.º 9
0
def startPlugin(namePlugin): # the argument received is always a folder
	IJ.log('Plugin ' + namePlugin + ' started at ' + str(time.strftime('%Y%m%d-%H%M%S')))
	externalArguments = Macro.getOptions().replace('"','').replace(' ','')
	externalArguments = os.path.normpath(externalArguments)
	return externalArguments