def catchIJErrors(function): try: IJ.redirectErrorMessages() return function() except: logWindow = WindowManager.getFrame("Log") if not logWindow is None: error_message = logWindow.getTextPanel().getText() logWindow.close() return error_message
def update_menus(): try: IJ.redirectErrorMessages() IJ.run('Update Menus') except: error_message = 'Error updating menus' logWindow = WindowManager.getFrame("Log") if not logWindow is None: error_message = error_message + ': ' \ + logWindow.getTextPanel().getText() logWindow.close() print error_message global error error += 1
if processFilter == 2: IJ.run(dataImage,"Median...", "radius=2 stack") theImage.close() ## Now runs the object counter on the processed tile params = ("volume surface nb_of_obj._voxels " + "nb_of_surf._voxels integrated_density mean_gray_value " + "std_dev_gray_value median_gray_value minimum_gray_value " + "maximum_gray_value centroid mean_distance_to_surface " + "std_dev_distance_to_surface median_distance_to_surface centre_of_mass " + "bounding_box dots_size=5 font_size=10 " + "redirect_to=none") IJ.run("3D OC Options", params) params = ("threshold=" + str(intThreshold) + " slice=1 min.=" + str(sizeThreshold) + " max.=24903680 objects surfaces statistics") IJ.redirectErrorMessages(True) IJ.run(dataImage, "3D Objects Counter", params) dataImage.changes = False dataImage.close() ## Saves the results table, surfaces image output, and run configuration surfacesImage = WindowManager.getImage("Surface map of " + dataImage.getTitle()) IJ.run(surfacesImage,"8-bit","") surfacesImage = make_image_binary(surfacesImage) IJ.saveAsTiff(surfacesImage,parentLSMFilePath + "_tiles/surfaces/C" + str(analysisChannel) + "-tile_" + str(tile) + ".tif") surfacesImage.close() objectsImage = WindowManager.getImage("Objects map of " + dataImage.getTitle()) IJ.run(objectsImage,"8-bit","") objectsImage = make_image_binary(objectsImage) IJ.saveAsTiff(objectsImage,parentLSMFilePath + "_tiles/maps/C" + str(analysisChannel) + "-tile_" + str(tile) + ".tif") objectsImage.close()
def PrepareDatabase(minw, maxw, baseDir, aspectRatio, majorWidth, majorHeight): outputpath = baseDir + "/" + str(majorWidth) + "_" + str(majorHeight) + "_orig.tif" #initialize stacks and labels stackScaled = [] stackOrig = ImageStack(majorWidth, majorHeight) imageNames = [] for i in range(minw, maxw+1): stackScaled.append(ImageStack(i, int(round(i/aspectRatio, 0)))) imageNames.append('') counter = 0 # initialize zip file for originals zf = zipfile.ZipFile(baseDir + "/originals.zip", mode='w', compression=zipfile.ZIP_DEFLATED, allowZip64=1) zf.writestr('from_string.txt', 'hello') zf.close() zf = zipfile.ZipFile(baseDir + "/originals.zip", mode='a', compression=zipfile.ZIP_DEFLATED, allowZip64=1) for root, dirs, files in os.walk(str(baseDir)): for f1 in files: if f1.endswith(".jpg") or f1.endswith(".jpe") or f1.endswith(".jpeg"): id = root + "/" + f1 IJ.redirectErrorMessages() IJ.redirectErrorMessages(1) imp = IJ.openImage(id) if imp is None: print "Couldn\'t open image from file:", id continue # skip non RGBimages if imp.getProcessor().getNChannels() != 3: print "Skipping non RGB image:", id continue #skip images with different aspect ratio width = imp.getWidth() height = imp.getHeight() ratio = round(float(width)/float(height), 2) # this makes the ratio filering approximate, minor variations in image dimensions will be ignored if ratio != aspectRatio: IJ.log("Skipping image of size: " + str(width) + "," + str(height)) continue # now scale the image within a given range scale = Scale(imp.getProcessor()) IJ.log("Scaling image " + str(counter) + " " + str(id)) for i in range(minw, maxw+1): stackScaled[i-minw].addSlice(None, ScaleImageToSize(scale, i, int(round(i/aspectRatio, 0)))) imageNames[i-minw] += str(id) + ";" # save the originals to a temp directory scaledOrig = ImagePlus(None, ScaleImageToSize(scale, majorWidth, majorHeight)) SaveToZip(zf, scaledOrig, baseDir, counter) counter += 1 zf.close() # save the stacks for i in range(minw, maxw+1): impScaled = ImagePlus(str(minw) + "_" + str(int(round(i/aspectRatio, 0))), stackScaled[i-minw]) impScaled.show() #print imageNames impScaled.setProperty('Info', imageNames[i-minw][:-1]) fs = FileSaver(impScaled) filepath = baseDir + "/" + str(i) + "_" + str(int(round(i/aspectRatio, 0))) + ".tif" IJ.log("Saving output stack" + str(filepath)) fs.saveAsTiffStack(filepath) #IJ.save(impScaled, filepath); IJ.log("Done")
'Image>Color>Hello, "Cello", Cello') fake_plugin_jar(temporary_folder + '/test_2.jar', 'Image>Color>Hello, "Bello", Bello' + "\n" + 'Image>Color>Hello, "Allo", Bello' + "\n" + 'Plugins>bla>blub>, "Eldo", Rado' + "\n" + 'Plugins>bla>blub>, "Bubble", Rado' + "\n" + 'Plugins, "Cello", xyz' + "\n" + 'Plugins, "Abracadabra", abc') # reset the plugins folder to the temporary directory System.setProperty('plugins.dir', temporary_folder); # Launch ImageJ IJ.redirectErrorMessages() ij = ImageJ() error = 0 # Must show Duplicate command error logWindow = WindowManager.getFrame("Log") if logWindow is None: print 'No error adding duplicate entries' error += 1 else: logText = logWindow.getTextPanel().getText() if not 'Duplicate command' in logText: print 'Error adding duplicate entries, but the wrong one' error += 1 logWindow.close()
gd.addStringField("String to identify your input images", "_deconv") gd.addRadioButtonGroup("Output", outDirChoices, 3, 1, outDirChoices[0]) gd.addRadioButtonGroup("Threshold Settings", thresholdChoices, 3, 1, thresholdChoices[0]) gd.addRadioButtonGroup("Overwrite", overwriteChoices, 2, 1, overwriteChoices[0]) gd.addCheckboxGroup(2, 1, mipChoices, [False, False], ["Do you want maximum intensity projections of your images?"]) gd.showDialog() if gd.wasCanceled(): exit() fileID = gd.getNextString() outDirPref = gd.getNextRadioButton() thresholdPref = gd.getNextRadioButton() overwritePref = gd.getNextRadioButton() mipPrefTIFF = gd.getNextBoolean() mipPrefJPG = gd.getNextBoolean() IJ.redirectErrorMessages(True) inDir = IJ.getDirectory("Choose Directory Containing Input Files") if inDir is None: exit('No input directory selected!') if outDirPref == outDirChoices[2]: outDir = inDir else: outDir = IJ.getDirectory("Choose Directory For Output") if outDir is None: exit('No output directory selected!') if outDirPref == outDirChoices[1]: for dirpath, dirnames, filenames in os.walk(inDir): if any([fileExt in f for f in filenames]): structure = os.path.join(outDir, dirpath[len(inDir):])
def PrepareDatabase(minw, maxw, baseDir, aspectRatio, majorWidth, majorHeight): outputpath = baseDir + "/" + str(majorWidth) + "_" + str( majorHeight) + "_orig.tif" #initialize stacks and labels stackScaled = [] stackOrig = ImageStack(majorWidth, majorHeight) imageNames = [] for i in range(minw, maxw + 1): stackScaled.append(ImageStack(i, int(round(i / aspectRatio, 0)))) imageNames.append('') counter = 0 # initialize zip file for originals zf = zipfile.ZipFile(baseDir + "/originals.zip", mode='w', compression=zipfile.ZIP_DEFLATED, allowZip64=1) zf.writestr('from_string.txt', 'hello') zf.close() zf = zipfile.ZipFile(baseDir + "/originals.zip", mode='a', compression=zipfile.ZIP_DEFLATED, allowZip64=1) for root, dirs, files in os.walk(str(baseDir)): for f1 in files: if f1.endswith(".jpg") or f1.endswith(".jpe") or f1.endswith( ".jpeg"): id = root + "/" + f1 IJ.redirectErrorMessages() IJ.redirectErrorMessages(1) imp = IJ.openImage(id) if imp is None: print "Couldn\'t open image from file:", id continue # skip non RGBimages if imp.getProcessor().getNChannels() != 3: print "Converting non RGB image:", id if imp.getStackSize() > 1: StackConverter(imp).convertToRGB() else: ImageConverter(imp).convertToRGB() #skip images with different aspect ratio width = imp.getWidth() height = imp.getHeight() ratio = round( float(width) / float(height), 2 ) # this makes the ratio filering approximate, minor variations in image dimensions will be ignored if ratio != aspectRatio: IJ.log("Skipping image of size: " + str(width) + "," + str(height)) continue # now scale the image within a given range scale = Scale(imp.getProcessor()) IJ.log("Scaling image " + str(counter) + " " + str(id)) for i in range(minw, maxw + 1): stackScaled[i - minw].addSlice( None, ScaleImageToSize(scale, i, int(round(i / aspectRatio, 0)))) imageNames[i - minw] += str(id) + ";" # save the originals to a temp directory scaledOrig = ImagePlus( None, ScaleImageToSize(scale, majorWidth, majorHeight)) SaveToZip(zf, scaledOrig, baseDir, counter) counter += 1 zf.close() # save the stacks for i in range(minw, maxw + 1): impScaled = ImagePlus( str(minw) + "_" + str(int(round(i / aspectRatio, 0))), stackScaled[i - minw]) impScaled.show() #print imageNames impScaled.setProperty('Info', imageNames[i - minw][:-1]) fs = FileSaver(impScaled) filepath = baseDir + "/" + str(i) + "_" + str( int(round(i / aspectRatio, 0))) + ".tif" IJ.log("Saving output stack" + str(filepath)) fs.saveAsTiffStack(filepath) #IJ.save(impScaled, filepath); IJ.log("Done")