def getTable(): ''' Check if a table exists otherwise open a new one''' ## Check if we can get a table window if IJ.getFullVersion() >= "1.53g": # try to get any active table tableWindow = WindowManager.getActiveTable( ) # this function requires 1.53g (or at least not working with 1.53c), return None if no table else: # Fallback on fetching either a window called Annotations or Annotations.csv as in previous plugin version win = WindowManager.getWindow("Annotations") win2 = WindowManager.getWindow( "Annotations.csv") # upon saving it adds this extension if win: tableWindow = win elif win2: tableWindow = win2 else: tableWindow = None ## If a table window then get its table, otherwise new table. In this case, its name is set later return tableWindow.getResultsTable() if tableWindow else ResultsTable()
def __init__(self): if IJ.getFullVersion() < "1.53b": message = "ImageJ with at least version 1.53b required. Update with Help > Update ImageJ..." IJ.error(message) raise Exception(message) super(TableModel, self).__init__() self.headers = ["Group", "Name"] groupNames = Roi.getGroupNames() # groupNames can be None ! groupNames = groupNames.split(",") if groupNames else [ "ExampleName-doubleClick to edit" ] # groupNames is a list self.nRows = len(groupNames) self.columns = [[], []] # 2 columns self.columns[0] = range(1, len(groupNames) + 1) self.columns[1] = groupNames
def actionPerformed(self, event): if IJ.getFullVersion() < "1.53g": IJ.error("This plugin requires ImageJ version 1.53g minimum.\n Update using Help > Update ImageJ...") return tableWindow = WindowManager.getActiveTable() # this function requires the 1.53g (or at least not working with 1.53c) if not tableWindow: return # Get column Category table = tableWindow.getResultsTable() column = table.getColumnAsVariables("Category") columnString = [str(item) for item in column] # Plot Pie Plot for this column pieChart = PieChart("Category", columnString) pieChart.showFrame("Data-distribution")
from QualiAnnotations.Charts import PieChart from ij.gui import GenericDialog from ij import IJ, WindowManager if IJ.getFullVersion() < "1.53g": IJ.error( "This plugin requires ImageJ version 1.53g minimum.\n Update using Help > Update ImageJ..." ) raise Exception("ImageJ version 1.53g minimum required") tableWindow = WindowManager.getActiveTable( ) # this function requires the 1.53g (or at least not working with 1.53c) #print tableWindow if not tableWindow: IJ.error("No open table") else: # List column headers table = tableWindow.getResultsTable() headers = table.getHeadings() # Generate dialog with dropdown for column selection dialog = GenericDialog("PieChart from table column") dialog.addChoice("Data column", headers, headers[0]) dialog.addMessage( """Hover the mouse over the plot to view absolute and relative (%) values\n Right-click to set colors, export to PNG...\n Note: BarCharts usually provide better distinction than PieCharts for sectors with similar sizes (see Help).""" )
On my version of ImageJ (1.52n99) 2019-06-15 setting res.showRowNumbers() as True or False made no difference """ from ij.measure import ResultsTable from ij import IJ from ij.plugin.filter import Analyzer import jmFijiGen as jmg # start cean IJ.run("Close All") jmg.close_open_non_image_window("Results") jmg.close_open_non_image_window("ROI Manager") # open our image imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif") Analyzer.setOption("BlackBackground", True) imp.show() IJ.run("Convert to Mask") imp.show() IJ.run("Set Measurements...", "area perimeter shape display redirect=None decimal=3") IJ.run("Analyze Particles...", "size=20-Infinity circularity=0.2-1.00 display exclude clear add") # Note that this showed the result numbers independent of T/F below res = ResultsTable.getResultsTable() res.showRowNumbers(True) res.updateResults() print("ImageJ version " + IJ.getFullVersion())
# has to be the first line from __future__ import print_function import os, sys from ij import IJ, WindowManager from ij.io import OpenDialog from ij.process import ImageConverter # by default convert to 8-bit will scale, i need to turn ot off. See: https://ilovesymposia.com/2014/02/26/fiji-jython/ # see: https://imagej.nih.gov/ij/developer/api/ij/process/ImageConverter.html # Set true to scale to 0-255 when converting short to byte or float to byte and to 0-65535 when converting float to short. from loci.plugins import BF # lifeline version is 1.51n99 # newer (April 2020) version is 1.52p99 fijiVersion = IJ.getFullVersion() fijiVersion = str(fijiVersion) print('simpleConvert() is running in ImageJ/Fiji:', fijiVersion) goodVersion = fijiVersion.find('1.51') != -1 def myConvert(path='', imp=None): if path == '' and imp is None: # NOT USED # ask user for file. I do not know how to handle when users hits cancel??? Script will just fail notUsedBy_oxs = 'Open a two-channel deconvoluted .oir file' path = OpenDialog(notUsedBy_oxs).getPath() if len(path) > 0: print(' user selected path:', path) fileName = os.path.basename(path)
Requirements : - IJ-OpenCV (from the updater) TO DO : - Images with overlay in Stack : change to the easier ij.plugin.ImagesToStack that use a list to make the stack. No need to precise the size.. ''' # Python from __future__ import division # ImageJ from ij import IJ,ImagePlus, ImageStack from ij.plugin.filter import MaximumFinder #from ij.gui import Roi, PointRoi if IJ.getFullVersion()<"1.52o": IJ.error("Please update ImageJ to min v1.52o. Help>Update ImageJ...") # OpenCV try: from org.bytedeco.javacpp.opencv_imgproc import matchTemplate, threshold, CV_THRESH_TOZERO from org.bytedeco.javacpp.opencv_core import Mat, Scalar, Point, minMaxLoc, subtract # UNUSED normalize, NORM_MINMAX, CV_8UC1, CV_32FC1 from org.bytedeco.javacpp import DoublePointer except: IJ.error("Missing OpenCV dependencies. Make sure to activate 'IJ-OpenCV plugins' update site.") # Java from java.lang import Float #used to convert BytesToFloat
def defaultActionSequence(self): """ Central function (DO NOT OVERWRITE) called if a button is clicked or shortcut called It trigger the following actions: - getting the current table - checking the GUI state (checkboxes, dropdown...) - running measurements if measure is selected - setting ROI attribute (if roi) - incrementing table counter - adding image directory and name to table - filling columns from GUI state using custom fillTable() - switching to next slice - displaying the annotation GUI to the front, important to catch next keyboard shortcuts """ try: imp = IJ.getImage() # get current image except: # no image: just stop the execution then return # Get current table table = getTable() table.showRowNumbers(True) # Check options, use getCheckboxes(), because the checkbox plugin have other checkboxes checkboxes = self.getCheckboxes() # Initialize Analyzer if self.runMeasure: analyzer = Analyzer(imp, table) analyzer.setMeasurement(Measurements.LABELS, False) # dont add label to table # Check if existing roi manager rm = RoiManager.getInstance() indexes = rm.getSelectedIndexes() if rm else [ ] # Check if roi selected if indexes: # Loop over selected ROI for index in indexes: # set selected features as property of rois roi = rm.getRoi(index) imp.setRoi(roi) # Run measure for the ROI if self.runMeasure: # Automatically increment counter analyzer.measure() # as selected in Set Measurements else: table.incrementCounter( ) # Automatically done if runMeasure #table.addValue("Index", table.getCounter() ) for key, value in getImageDirAndName(imp).iteritems(): table.addValue(key, value) # Add selected items (implementation-specific) self.fillTable(table) # Read comment stringField = self.getStringFields()[0] table.addValue("Comment", stringField.text) # Add roi name to the table + set its property table.addValue("Roi", roi.getName()) # Add roi name to table setRoiProperties(roi, table) # No roi selected in the Manager else: if self.runMeasure: # also automatically increment counter analyzer.measure() # as selected in Set Measurements else: table.incrementCounter() # Automatically done if runMeasure #table.addValue("Index", table.getCounter() ) for key, value in getImageDirAndName(imp).iteritems(): table.addValue(key, value) # Add selected items (implementation-specific) self.fillTable(table) # Read comment stringField = self.getStringFields()[0] table.addValue("Comment", stringField.text) # Check if an active Roi, not yet present in Manager roi = imp.getRoi() if roi is not None: roi.setPosition(imp) rm = getRoiManager() rm.addRoi(roi) # get back the roi from the manager to set properties roiBis = rm.getRoi(rm.getCount() - 1) roiName = roiBis.getName() table.addValue("Roi", roiName) # Add roi name to table setRoiProperties(roiBis, table) title = table.getTitle() if table.getTitle( ) else "Annotations" # getTitle is None for newly generated table table.show(title) # Update table #table.updateResults() # only for result table but then addValue does not work ! # Go to next slice doNext = checkboxes[-1].getState() if doNext: if self.browseMode == "stack": nextSlice(imp, self.getSelectedDimension()) elif self.browseMode == "directory": NextImageOpener().run("forward") # Bring back the focus to the button window (otherwise the table is in the front) if not IJ.getFullVersion().startswith("1.52p"): WindowManager.toFront(self) # prevent some ImageJ bug with 1.52p