Exemplo n.º 1
0
def run():
    gd = GenericDialogPlus("ND2 Conversion Tool")
    gd.addMessage("This plugin uses BioFormats to convert ND2 images to JPEG for further processing in ImageJ.")
    gd.addDirectoryOrFileField("Input: ", "G:\\Subdir testing\\") #srcDir
    gd.addDirectoryOrFileField("Output: ", "G:\\Subdir testing\\") #dstDir
    gd.addStringField("File name contains: ", "") #nameContains
    gd.addCheckbox("Preserve directory structure?", True) #keepDirs
    gd.addCheckbox("Run in headless mode?", True) #anneBoleyn 
    gd.addCheckbox("Overwrite existing output files?", True)
    gd.showDialog()
    if gd.wasCanceled():
        return
    srcDir = gd.getNextString()
    dstDir = gd.getNextString()
    nameContains = gd.getNextString()
    keepDirectories = gd.getNextBoolean()
    anneBoleyn = gd.getNextBoolean()
    overOut = gd.getNextBoolean()
    IJ.run("Input/Output...", "jpeg=100")
    for root, directories, filenames in os.walk(srcDir):
        for filename in filenames:
            # Check for file extension
            if not filename.endswith(".nd2"):
                continue
            # Check for file name pattern
            if nameContains not in filename:
                continue
            process(srcDir, dstDir, nameContains, root, filename, keepDirectories, anneBoleyn, overOut)
Exemplo n.º 2
0
def get_user_params(event):
    """ Allows user to select file and user parameters

    Parameters
    ----------
    event : Event
        Waits for get_user_params_JB JButton to be pressed
    
    Returns
    -------
    dict
        Dict containing filename, number of Gaussians to fit,
        % of dataset to import, whether to specify grey value
        limits, minimum grey value and maximum grey value to 
        consider (optional)
    """
    # Open user dialog
    gui = GenericDialogPlus("Define user parameters")
    gui.addFileField("Image filename", "Select image file")
    gui.addNumericField("Number of Gaussians to fit: ", 2, 0)
    gui.addNumericField("Percentage of dataset to import: ", 15, 0)
    gui.addCheckbox("Specify grey value limits?", False)
    gui.addNumericField("Min grey value (optional): ", 0, 0)
    gui.addNumericField("Max grey value (optional): ", 255, 0)
    gui.showDialog()

    # Extract user parameters
    if gui.wasOKed():
        user_params = {}  # empty dict
        user_params['img_fname'] = str(gui.getNextString())
        user_params['n_gaussians'] = int(gui.getNextNumber())
        user_params['pct_stack_import'] = float(gui.getNextNumber())
        user_params['specify_gv'] = gui.getNextBoolean()
        user_params['min_gv'] = float(gui.getNextNumber())
        user_params['max_gv'] = float(gui.getNextNumber())

    # Create results directory
    results_dir = os.path.splitext(user_params['img_fname'])[0] + "_results"
    if os.path.isdir(results_dir) == False:
        os.mkdir(results_dir)
    print("Results directory: {}".format(results_dir))

    # Write user parameters to text file
    user_params_fname = os.path.join(results_dir, "Users_Params.csv")
    with open(user_params_fname, "wb") as f:
        w = csv.DictWriter(f, user_params.keys())
        w.writeheader()
        w.writerow(user_params)

    # Write directory to look for user params to text file in main/
    temp_user_dir = os.path.join(os.path.dirname(__file__),
                                 "temp_user_dir.txt")
    if os.path.isfile(temp_user_dir) == True:
        os.remove(temp_user_dir)  # delete temp_user_dir.txt if present
    f = open(temp_user_dir, "w")
    f.write(user_params_fname)
    f.close()

    return user_params
Exemplo n.º 3
0
def make_dialog():

	parameters = {}

	gd = GenericDialogPlus("Grid Stitch SDC Data")
	gd.addMessage(  "Warning!\n"\
					"In order to display a fused image upon completion of stitching\n"\
					"please disable Fiji's ImageJ2 options. When enabled an ImageJ\n"\
					"exception will be displayed upon completion. This exception can\n"
					"be safely ignored.")
	gd.addMessage(  "Information\n"\
					"This plugin is a wrapper around the Fiji 'Grid Stitching' plugin.\n"\
					"It allows tiles generated in SlideBook to be directly stitched by\n"\
					"by first writing out the individual tiles, executing the 'Grid Stitching'\n"\
					"plugin and writing the fused image to disk.")
	gd.addMessage("")										
	gd.addNumericField("grid_size_x", 3, 0)
	gd.addNumericField("grid_size_y", 3, 0)
	gd.addCheckbox("Select channel",False)
	gd.addNumericField("", 0, 0)		
	gd.addCheckbox("Are the Z slices separate files?",False)
	gd.addDirectoryField("directory", "", 50)
	
	gd.showDialog()
	if (gd.wasCanceled()): return
		
	parameters['gridX'] = int(math.ceil(gd.getNextNumber()))
	parameters['gridY'] = int(math.ceil(gd.getNextNumber()))
	parameters['select_channel'] = gd.getNextBoolean()
	parameters['channel'] = None
	if parameters['select_channel']:
		parameters['channel'] = int(gd.getNextNumber())
	parameters['separate_z'] = gd.getNextBoolean()
	directory = str(gd.getNextString())	
	if directory is None:
	# User canceled the dialog
		return None
	else:
		directory = os.path.abspath(directory)
		parameters['directory'] = directory + os.path.sep

	return parameters
Exemplo n.º 4
0
def get_parameters(p):
  gd = GenericDialogPlus("Please enter parameters")

  for k in p['expose_to_gui']['value']:
    if p[k]['type'] == 'boolean':
      gd.addCheckbox(k, p[k]['value'])
    elif p[k]['type'] == 'folder':
      gd.addDirectoryField(k, p[k]['value'], 100)	
    elif p[k]['type'] == 'file':
      gd.addFileField(k, p[k]['value'], 100)	
    elif p[k]['type'] == 'string':
      if p[k]['choices']:
        gd.addChoice(k, p[k]['choices'], p[k]['value'])	
      else:
        gd.addStringField(k, p[k]['value'])	 
    elif p[k]['type'] == 'int':
      if p[k]['choices']:
        gd.addChoice(k, p[k]['choices'], p[k]['value'])	
      else:
        gd.addNumericField(k, p[k]['value'], 0)	 
    elif p[k]['type'] == 'float':
      gd.addNumericField(k, p[k]['value'], 2)
  
  gd.showDialog()
  if gd.wasCanceled():
    return

  for k in p['expose_to_gui']['value']:
    if p[k]['type'] == 'boolean':
      p[k]['value'] = gd.getNextBoolean()
    elif p[k]['type'] == 'folder' or p[k]['type'] == 'file':
      p[k]['value'] = gd.getNextString()
    elif p[k]['type'] == 'string':
      if p[k]['choices']:
        p[k]['value'] = gd.getNextChoice()	
      else:
        p[k]['value'] = gd.getNextString()	 
    elif p[k]['type'] == 'int':
      if p[k]['choices']:
        p[k]['value'] = int(gd.getNextChoice())	
      else:
        p[k]['value'] = int(gd.getNextNumber()) 
    elif p[k]['type'] == 'float':
        p[k]['value'] = gd.getNextNumber()
    
  return p
Exemplo n.º 5
0
Win.addCheckbox("Add_ROI detected to ROI manager",
                prefs.getInt("AddRoi", True))
Win.addCheckbox("Show_result table", prefs.getInt("ShowTable", False))
Win.addMessage("""If you use this plugin please cite :
Laurent SV Thomas, Jochen Gehrig
bioRxiv 619338; doi: https://doi.org/10.1101/619338""")
Win.addHelp(
    "https://github.com/multi-template-matching/MultiTemplateMatching-Fiji/wiki"
)

Win.showDialog()

if Win.wasOKed():
    template = Win.getNextImage()
    image = Win.getNextImage()
    flipv = Win.getNextBoolean()
    fliph = Win.getNextBoolean()
    angles = Win.getNextString()
    method = Win.getNextChoice()
    n_hit = int(Win.getNextNumber())
    score_threshold = Win.getNextNumber()
    #tolerance   = Win.getNextNumber()
    tolerance = 0
    max_overlap = Win.getNextNumber()
    add_roi = Win.getNextBoolean()
    show_table = Win.getNextBoolean()

    # Save for persistence
    ImageName = image.getTitle()
    prefs.put("Template", template.getTitle())
    prefs.put("Image", ImageName)
gd.addMessage("Start by choosing a registration directory or images directory!")
statusf=gd.getMessage()
gd.showDialog()
if gd.wasCanceled():
	sys.exit("User cancelled!")
# Process Dialog Choices
rootDir=gd.getNextString()
os.chdir(rootDir)
refBrain=gd.getNextString()
image=gd.getNextString()
image=relpath(image,rootDir)
print refBrain
refBrain=relpath(refBrain,rootDir)
print refBrain

affine=gd.getNextBoolean()
ch01=gd.getNextBoolean()
warp=gd.getNextBoolean()
ch02=gd.getNextBoolean()
reformat=gd.getNextBoolean()
ch03=gd.getNextBoolean()
munger_actions=""
if affine:
	munger_actions+="-a "
if warp:
	munger_actions+="-w "
if reformat:
	channels=''
	if ch01:
		channels+='01'
	if ch02:
Exemplo n.º 7
0
gdp.addStringField("Channel 2:", 'B', 8)
gdp.addStringField("Channel Z/Channel W:", 'C', 8)
gdp.addToSameRow()
gdp.addStringField("R/R0:", 'D', 8)
gdp.showDialog()
if gdp.wasOKed():
    dest = gdp.getNextString().strip()
    ProFolder = gdp.getNextString().strip()
    Procsv = gdp.getNextString().strip()
    radius = int(gdp.getNextString().strip())
    interval = int(gdp.getNextString().strip())
    errorval = gdp.getNextString().strip()
    f_f = gdp.getNextRadioButton()
    back_state = gdp.getNextString().strip()
    back_val = int(gdp.getNextString().strip())
    blur_state = gdp.getNextBoolean()
    blur_val = int(gdp.getNextString().strip())
    r_start = int(gdp.getNextString().strip())
    r_end = int(gdp.getNextString().strip())
    ch1_str = gdp.getNextString().strip()
    ch2_str = gdp.getNextString().strip()
    ch12_str = gdp.getNextString().strip()
    rr0_str = gdp.getNextString().strip()

imp_save = IJ.getImage()
Save_Title = imp_save.getTitle()

try:
    erroval = int(errorval)
except ValueError:
    errorval = errorval
Exemplo n.º 8
0
gd.addChoice("Nuclear thresholding method", methodsList, nucMethod)
gd.addCheckbox("Threshold nuclei by stack?", analyzeNucStack)
gd.addCheckbox("Are the cardiomyocyte images brightfield?", brightfield)
gd.addChoice("Cardiomyocyte thresholding method", methodsList,  cmMethod)
gd.addCheckbox("Threshold cardiomyocyes by stack?", analyzeCmStack)
gd.addNumericField("Rows per well", rowNo, 0)
gd.addNumericField("Columns per well", colNo, 0)
gd.addNumericField("Nuclear minimum size (pixels)", nucMinSize, 0)
gd.addNumericField("Cardiomyocyte minimum size (pixels)", cmMinSize, 0)
gd.showDialog()
folderPath = gd.getNextString() + "/"
formatString = gd.getNextString()
groupBy = re.findall(r"\w+", gd.getNextString())
nucChannel = gd.getNextString()
cmChannel = gd.getNextString()
stitched = gd.getNextBoolean()
nucMethod = gd.getNextChoice()
analyzeNucStack = gd.getNextBoolean()
brightfield = gd.getNextBoolean()
cmMethod = gd.getNextChoice()
analyzeCmStack = gd.getNextBoolean()
rowNo = int(gd.getNextNumber())
colNo = int(gd.getNextNumber())
nucMinSize = int(gd.getNextNumber())
cmMinSize = int(gd.getNextNumber())
allFileNames = os.listdir(folderPath)
jsonStoreDict = {"folderPath": folderPath,
				"formatString":formatString,
				"groupBy": ','.join(groupBy),
				"nucChannel": nucChannel,
				"cmChannel": cmChannel,
Exemplo n.º 9
0
Win.addMessage("Outputs")
Win.addCheckbox("Open_images as a stack (must have identical sizes)", prefs.getInt("ShowImages", True))
Win.addCheckbox("Add_ROI detected  to ROI Manager", prefs.getInt("AddRoi", True))
Win.addCheckbox("Show_result table", prefs.getInt("ShowTable", False))
Win.addMessage("""If you use this plugin please cite :
Laurent SV Thomas, Jochen Gehrig
bioRxiv 619338; doi: https://doi.org/10.1101/619338""")
Win.addHelp("https://github.com/multi-template-matching/MultiTemplateMatching-Fiji/wiki")

Win.showDialog()

if Win.wasOKed():
	TemplatePath = Win.getNextString()
	ImagePath    = Win.getNextString()
	RoiPath      = Win.getNextString()
	flipv  = Win.getNextBoolean()
	fliph  = Win.getNextBoolean()
	angles = Win.getNextString()
	method = Win.getNextChoice()
	n_hit  = int(Win.getNextNumber())
	score_threshold = Win.getNextNumber()
	#tolerance   = Win.getNextNumber()
	tolerance = 0
	max_overlap = Win.getNextNumber()
	show_images = Win.getNextBoolean()
	add_roi     = Win.getNextBoolean()
	show_table  = Win.getNextBoolean()
	
	# Save for persistence
	prefs.put("TemplatePath", TemplatePath)
	prefs.put("ImagePath", ImagePath)
Exemplo n.º 10
0
import os, shutil
import uuid
import sys

gdp=GenericDialogPlus("File Randomizer")
file_type = gdp.getNextString()
gdp.addStringField("File Extension ", '.tif',5)
x=gdp.addDirectoryField("Source:", " ")
gdp.addDirectoryField("Destination:", "(optional)")
gdp.addCheckbox("Copy & Move",False)
gdp.showDialog()
if gdp.wasOKed():
	file_type = gdp.getNextString().strip()
	source_path = gdp.getNextString().strip()
	dest_path = gdp.getNextString().strip()
	copymove=gdp.getNextBoolean()
	if dest_path == '(optional)':
		dest_path = source_path

else:
	exit()

##makes a new directory in the destination directory, called randomized.
key='key.csv'
r_key= os.path.join(dest_path,key)

if copymove ==True:
	randomized = 'randomized'
	path = os.path.join(dest_path,randomized)
	path = path+'/'
	try:
               '(' + str(progress[2]) + '/' + str(progress[1]) + ')', italicFont)
gdp.addHelp("https://github.com/JohnSargeant-rgb")
gdp.showDialog()
if gdp.wasOKed():
    dest = gdp.getNextString().strip()
    ProFolder = gdp.getNextString().strip()
    Quant = gdp.getNextString().strip()
    Quant_MM = gdp.getNextString().strip()
    transport_c = gdp.getNextChoice()
    file_type = gdp.getNextString().strip()
    golgi_c = gdp.getNextChoice()
    extension = gdp.getNextString().strip()
    zoom_to = int(gdp.getNextChoice())
    radius = gdp.getNextString().strip()
    color_scale = gdp.getNextChoice()
    always_select = gdp.getNextBoolean()
    always_auto = gdp.getNextBoolean()
    mean_max_det = gdp.getNextBoolean()
    man_bck_det = gdp.getNextBoolean()
    auto_pos_det = gdp.getNextBoolean()
    xpos_det = gdp.getNextString().strip()
    ypos_det = gdp.getNextString().strip()

    new_selected_values = {
        "ProFolder_def": ProFolder,
        "Quant_def": Quant,
        "Quant_MM_def": Quant_MM,
        "tran_def": transport_c,
        "file_def": file_type,
        "golgi_def": golgi_c,
        "ext_def": extension,
Exemplo n.º 12
0
gdp=GenericDialogPlus("File Derandomizer")
gdp.addFileField("'Key' path :", " ")
gdp.addFileField("Data file :", " ")
gdp.addDirectoryField("Derandomized path", "(optional)")
gdp.addDirectoryField("Processed Image Folder", " ")
gdp.addCheckbox("Derandomize Data File", True)
gdp.addCheckbox("Derandomize Image Folder", False)

gdp.showDialog()
if gdp.wasOKed():
	key_path = gdp.getNextString().strip()
	data_path = gdp.getNextString().strip()
	deR_path = gdp.getNextString().strip()
	pi_path= gdp.getNextString().strip()
	ddf=gdp.getNextBoolean()
	dif=gdp.getNextBoolean()
	if deR_path == "(optional)":
		deR_path = os.path.dirname(data_path) 
else:
	exit()


# function to return key for any value
def get_key(val):
    for key, value in random.items():
         if val == value:
             return key

def replace(text,dic):
	"""Replaces values with keys"""
Exemplo n.º 13
0
        "Start by choosing a registration directory or images directory!")
    statusf = gd.getMessage()
    gd.showDialog()
    if gd.wasCanceled():
        sys.exit("User cancelled!")
    # Process Dialog Choices
    rootDir = gd.getNextString()
    os.chdir(rootDir)
    refBrain = gd.getNextString()
    image = gd.getNextString()
    image = relpath(image, rootDir)
    print refBrain
    refBrain = relpath(refBrain, rootDir)
    print refBrain

    affine = gd.getNextBoolean()
    ch01 = gd.getNextBoolean()
    warp = gd.getNextBoolean()
    ch02 = gd.getNextBoolean()
    reformat = gd.getNextBoolean()
    ch03 = gd.getNextBoolean()
    munger_actions = ""
    if affine:
        munger_actions += "-a "
    if warp:
        munger_actions += "-w "
    if reformat:
        channels = ''
        if ch01:
            channels += '01'
        if ch02: