def run(): # ensure no other windows are open and clear resultstable IJ.run("Close All") IJ.run("Clear Results", "") #Ask user for file to be converted srcDir = IJ.getFilePath("Select file to analyse") if not srcDir: return #open file IJ.open(srcDir) dstDir = os.path.dirname(srcDir) print("dstDir = " + dstDir) #open ROI manager, save ROI names as labels in measurements rm = RoiManager.getInstance() if not rm: rm = RoiManager() rm.runCommand("UseNames", "true") # set parameters to be measured IJ.run("Set Measurements...", "area mean integrated limit display redirect=None decimal=3") FOVlist = WindowManager.getIDList() chnls = IJ.getString( "Please enter which channels you would like to analyse. Example: 123 analyses channels 1, 2 and 3", '123') for FOV in FOVlist: imp = WindowManager.getImage(FOV) IJ.run(imp, "Arrange Channels...", "new=" + chnls) imp.close() imp2 = WindowManager.getCurrentImage() imageTitle = WindowManager.getImage(FOV).getTitle() newDir = imageTitle + ' ROIs' dirPath = os.path.join(dstDir, newDir) if not os.path.exists(dirPath): try: os.makedirs(dirPath) except OSError as e: if e.errno != errno.EEXIST: raise # clear ROI list before analysis rm.runCommand(imp2, "Deselect") rm.runCommand(imp2, "Delete") TMdata, nFrames = runTrackMate(imp2) if TMdata: iterateCoords(TMdata, nFrames, dirPath, imp2) imp2.changes = 0 imp2.close() #relabel() resultsDir = os.path.splitext(srcDir)[0] + ".csv" #while os.path.exists(resultsDir): #resultsDir = resultsDir+"_1"+".csv" IJ.saveAs("Results", resultsDir)
def run(): sId = IJ.getString("Filenames contain:", "T0000") srcDir = DirectoryChooser("Choose!").getDirectory() if not srcDir: # user canceled dialog return # Assumes all files have the same size stack = None for root, directories, filenames in os.walk(srcDir): for filename in filenames: # Skip non-TIFF files if not (sId in filename): continue print(filename) path = os.path.join(root, filename) # Upon finding the first image, initialize the VirtualStack imp = IJ.openImage(path) if stack is None: # stack = VirtualStack(imp.width, imp.height, None, srcDir) stack = ImageStack(imp.width, imp.height) # Add a slice to the virtual stack, relative to the srcDir # #stack.addSlice(path[len(srcDir):]) # Add a slice to the real stack # stack.addSlice(filename, imp.getProcessor()) # Make a ImagePlus from the stack ImagePlus("Stack from subdirectories", stack).show()
def run(): sId = IJ.getString("Filenames contain:", "T0000"); srcDir = DirectoryChooser("Choose!").getDirectory() if not srcDir: # user canceled dialog return # Assumes all files have the same size stack = None for root, directories, filenames in os.walk(srcDir): for filename in filenames: # Skip non-TIFF files if not (sId in filename): continue print(filename) path = os.path.join(root, filename) # Upon finding the first image, initialize the VirtualStack imp = IJ.openImage(path) if stack is None: # stack = VirtualStack(imp.width, imp.height, None, srcDir) stack = ImageStack(imp.width, imp.height) # Add a slice to the virtual stack, relative to the srcDir # #stack.addSlice(path[len(srcDir):]) # Add a slice to the real stack # stack.addSlice(filename, imp.getProcessor()) # Make a ImagePlus from the stack ImagePlus("Stack from subdirectories", stack).show()
def actionPerformed(self, event): outDir = IJ.getDirectory("Save category file in directory...") if not outDir: return # when cancelled filename = IJ.getString("Filename", "categories.txt") if not filename: return # when cancelled outPath = os.path.join(outDir, filename) listButtons = winButton.getPanel().getComponents() with open(outPath, "w") as catFile: for button in listButtons: catFile.write(button.getLabel().encode("utf-8") + "\n") # important to use UTF-8 otherwise troubles
def addCategoryComponent(self): """ Request a new category name, create the associated category component via the makeCategory method and update the dialog """ newCategory = IJ.getString("Enter new category name", "new category") if not newCategory: return # if Cancelled (ie newCat=="") or empty field just dont go further # Add new component to the gui for this category and repaint GUI newComponent = self.makeCategoryComponent(newCategory) if newComponent is None: return if not isinstance(newComponent, Component): raise TypeError("Expect a component to be added to the dialog") self.getPanel().add(newComponent) # component 1 is the panel self.pack() # recompute the layout and update the display
def actionPerformed(self, event): source = event.getSource() # test here if it is a button if isinstance(source, Button): # if type is a button get label, and check command, otherwise pass to GenericDialogPlus.actionPeformed sourceLabel = source.getLabel() if sourceLabel == CategoryDialog.ADD_CATEGORY: newCategory = IJ.getString("Enter new category name", "new category") if not newCategory: return # if Cancelled (ie newCat=="") or empty field just dont go further self.panel.add(TextField(newCategory)) # Add new text field with the new category self.pack() # recompute the layout and update the display # Anyway do the mother class usual action handling GenericDialogPlus.actionPerformed(self, event)
from sys import argv if len(argv) > 1: file = argv[1] else: file = "Stitching-overview.jpg" if len(argv) > 2: label = argv[2] else: label = '' ImageJ() screenshot = IJ.openImage(file) print "Opened", file, screenshot else: screenshot = IJ.getImage() label = IJ.getString('Label:', '') # make a gradient image ip = screenshot.getProcessor() w = ip.getWidth() h = ip.getHeight() u = int(0.99 * 255) l = int(0.5 * 255) def gray2rgb(value): return (value << 16) | (value << 8) | value # This is a trick: make a 1xh image (because calculation is slow in Python) and resize it to wxh from jarray import array
#IJ.run("Multiply...", "value=2.2") IJ.beep() gd = GenericDialog("Clockwise Rotation?") gd.addChoice("How Many Degrees",["0","90","180",'270'],"0") gd.showDialog() rotation = gd.getChoices().get(0).getSelectedItem() #in while loop while True: IJ.run("Stack to Images") IJ.run("Images to Stack", "name=Stack title=[] use") imp = IJ.getImage() myWait = ij.gui.WaitForUserDialog('Select Region to Load Full Res') myWait.show() region=IJ.getString("What to call region?", "") print(region) width=imp.getWidth() height=imp.getHeight() roi=imp.getRoi() xmin=roi.bounds.getMinX()/width xmax=roi.bounds.getMaxX()/width ymin=roi.bounds.getMinY()/height ymax=roi.bounds.getMaxY()/height print(dir(imp)) IJ.run("Make Composite", "display=Composite") IJ.run("Select All") #IJ.run("Multiply...", "value=2.0") IJ.run("Stack to RGB")
def getString(mssg, default): return IJ.getString(mssg, default)
from ij import IJ imp = IJ.getImage() title = imp.getTitle() title = title[:-4] interval_units = IJ.getString("Collection interval units: ", 'hrs') start_time = IJ.getString("Start time: ", '0') interval_by_units = IJ.getNumber("Collection interval in {}:".format(interval_units), 0.17) fontsize = IJ.getNumber("Fontsize:", 14) #get the directory containing the active image path = IJ.getDirectory("image") # If the active image is a duplicate of another image open, its path will be False and # will print as 'None'. If this is the case, have the user choose a directory to put the # timestamped tif if not path: IJ.log("Image has no source directory") path = IJ.getDirectory("Choose the directory to save the timestamped tif") else: pass height = imp.getHeight() width = imp.getWidth() size = imp.getImageStackSize() IJ.log("Image title: {}".format(title)) IJ.log("Save path: {}".format(path)) IJ.log("Height: {}".format(height)) IJ.log("Width: {}".format(width)) IJ.log("Size: {}".format(size))
#!/bin/sh """'exec "$(dirname "$0")"/ImageJ.sh --jython "$0" "$@" # (call again with fiji)""" from ij import IJ, ImageJ label = "Fiji Is Just ImageJ" if IJ.getInstance() == None: # called from the command line from sys import argv if len(argv) > 1: file = argv[1] else: file = "Stitching-overview.jpg" if len(argv) > 2: label = argv[2] ImageJ() screenshot = IJ.openImage(file) print "Opened", file, screenshot else: screenshot = IJ.getImage() label = IJ.getString("Label:", label) from fiji import Prettify_Wiki_Screenshot plugin = Prettify_Wiki_Screenshot() plugin.label = label plugin.run(screenshot.getProcessor())
#!/bin/sh ''''exec "$(dirname "$0")"/ImageJ.sh --jython "$0" "$@" # (call again with fiji)''' from ij import IJ, ImageJ label = 'Fiji Is Just ImageJ' if IJ.getInstance() == None: # called from the command line from sys import argv if len(argv) > 1: file = argv[1] else: file = "Stitching-overview.jpg" if len(argv) > 2: label = argv[2] ImageJ() screenshot = IJ.openImage(file) print "Opened", file, screenshot else: screenshot = IJ.getImage() label = IJ.getString('Label:', label) from fiji import Prettify_Wiki_Screenshot plugin = Prettify_Wiki_Screenshot() plugin.label = label plugin.run(screenshot.getProcessor())