Module ij
Package ij

# Class IJ

java.lang.Object
ij.IJ

public class IJ extends Object
This class consists of static utility methods.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static interface`
`IJ.ExceptionHandler`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`ALL_KEYS`
`static final char`
`angstromSymbol`
`static final int`
`CANCELED`
`static final int`
`COLOR`
Image display modes
`static final int`
`COMPOSITE`
Image display modes
`static boolean`
`debugMode`
Use setDebugMode(boolean) to enable/disable debug mode.
`static final char`
`degreeSymbol`
`static Font`
`font10`
SansSerif, plain, 10-point font
`static Font`
`font12`
SansSerif, plain, 12-point font
`static Font`
`font14`
SansSerif, plain, 14-point font
`static final int`
`GRAYSCALE`
Image display modes
`static boolean`
`hideProcessStackDialog`
`static final char`
`micronSymbol`
`static final String`
`URL`
Deprecated.
`static final String`
`URL2`
ImageJ website

## Constructor Summary

Constructors
Constructor
Description
`IJ()`

## Method Summary

Modifier and Type
Method
Description
`static void`
`addEventListener(IJEventListener listener)`
`static String`
`addSeparator(String path)`
`static boolean`
`altKeyDown()`
Returns true if the alt key is down.
`static String`
`append(String string, String path)`
Appends a string to the end of a file.
`static void`
`beep()`
Emits an audio beep.
`static boolean`
`controlKeyDown()`
Returns true if the control key is down.
`static ImagePlus`
`createHyperStack(String title, int width, int height, int channels, int slices, int frames, int bitdepth)`
Creates a new hyperstack.
`static ImagePlus`
`createImage(String title, int width, int height, int depth, int bitdepth)`
Creates a new image.
`static ImagePlus`
`createImage(String title, String type, int width, int height, int depth)`
Creates a new imagePlus.
`static ImagePlus`
`createImage(String title, String type, int width, int height, int channels, int slices, int frames)`
Creates a new hyperstack.
`static long`
`currentMemory()`
Returns the amount of memory currently being used by ImageJ.
`static String`
`d2s(double n)`
Converts a number to a formatted string using 2 digits to the right of the decimal point.
`static String`
`d2s(double n, int decimalPlaces)`
Converts a number to a rounded formatted string.
`static String`
`d2s(double x, int significantDigits, int maxDigits)`
Converts a number to a rounded formatted string.
`static void`
`deleteRows(int row1, int row2)`
Deletes 'row1' through 'row2' of the "Results" window, where 'row1' and 'row2' must be in the range 0-Analyzer.getCounter()-1.
`static void`
`doCommand(ImagePlus imp, String command)`
Runs a menu command on a separete thread, using the specified image.
`static void`
`doCommand(String command)`
Runs a menu command on a separete thread and returns immediately.
`static int`
`doWand(int x, int y)`
Equivalent to clicking on the current image at (x,y) with the wand tool.
`static int`
`doWand(int x, int y, double tolerance, String mode)`
Traces the boundary of the area with pixel values within 'tolerance' of the value of the pixel at the starting location.
`static int`
`doWand(ImagePlus img, int x, int y, double tolerance, String mode)`
This version of doWand adds an ImagePlus argument.
`static void`
`error(String msg)`
Displays a message in a dialog box titled "ImageJ".
`static void`
`error(String title, String msg)`
Displays a message in a dialog box with the specified title.
`static boolean`
`escapePressed()`
Returns true if the `Esc` key was pressed since the last ImageJ command started to execute or since resetEscape() was called.
`static void`
`exit()`
Aborts any currently running JavaScript, or use IJ.error(string) to abort a JavaScript with a message.
`static String`
`freeMemory()`
Returns a string something like "64K of 256MB (25%)" that shows how much of the available memory is in use.
`static Applet`
`getApplet()`
Returns the Applet that created this ImageJ or null if running as an application.
`static ClassLoader`
`getClassLoader()`
Returns the class loader ImageJ uses to run plugins or the system class loader if Menus.getPlugInsPath() returns null.
`static String`
`getDir(String title)`
Alias for getDirectory().
`static String`
`getDirectory(String title)`
Returns the path to the specified directory if `title` is "home" ("user.home"), "downloads", "startup", "imagej" (ImageJ directory), "plugins", "macros", "luts", "temp", "current", "default", "image" (directory active image was loaded from), "file" (directory most recently used to open or save a file), "cwd" (current working directory) or "preferences" (location of "IJ_Prefs.txt" file), otherwise displays a dialog and returns the path to the directory selected by the user.
`static String`
`getErrorMessage()`
Returns the last error message written by IJ.error() or null if there was no error since the last time this method was called.
`static String`
`getFilePath(String dialogTitle)`
Displays an open file dialog and returns the path to the choosen file, or returns null if the dialog is canceled.
`static String`
`getFullVersion()`
Returns the ImageJ version and build number as a String, for example "1.46n05", or 1.46n99 if there is no build number.
`static ImagePlus`
`getImage()`
Returns a reference to the active image, or displays an error message and aborts the plugin or macro if no images are open.
`static ImagePlus`
`getImage(Interpreter interpreter)`
The macro interpreter uses this method to call getImage().
`static ImageJ`
`getInstance()`
Returns a reference to the "ImageJ" frame.
`static String`
`getLog()`
Returns the contents of the Log window or null if the Log window is not open.
`static String[]`
`getLuts()`
Returns, as an array of strings, a list of the LUTs in the Image/Lookup Tables menu.
`static double`
`getNumber(String prompt, double defaultValue)`
Allows the user to enter a number in a dialog box.
`static ImageProcessor`
`getProcessor()`
Returns the active image or stack slice as an ImageProcessor, or displays an error message and aborts the plugin or macro if no images are open.
`static Object`
`getProperty(String key)`
Returns the object in IJ.properties associated with 'key', or null if 'key' is not found.
`static Dimension`
`getScreenSize()`
Returns the size, in pixels, of the primary display.
`static String`
`getString(String prompt, String defaultString)`
Allows the user to enter a string in a dialog box.
`static TextPanel`
`getTextPanel()`
Returns a reference to the "Results" window TextPanel.
`static String`
`getToolName()`
Returns the name of the current tool.
`static double`
`getValue(ImagePlus imp, String measurement)`
Returns a measurement result, where 'measurement' is "Area", "Mean", "StdDev", "Mode", "Min", "Max", "X", "Y", "XM", "YM", "Perim.", "BX", "BY", "Width", "Height", "Major", "Minor", "Angle", "Circ.", "Feret", "IntDen", "Median", "Skew", "Kurt", "%Area", "RawIntDen", "Ch", "Slice", "Frame", "FeretX", "FeretY", "FeretAngle", "MinFeret", "AR", "Round", "Solidity", "MinThr" or "MaxThr".
`static String`
`getVersion()`
Returns the ImageJ version number as a string.
`static void`
`handleException(Throwable e)`
Displays a stack trace.
`static boolean`
`is64Bit()`
Returns true if ImageJ is running a 64-bit version of Java.
`static boolean`
`isJava14()`
Always returns true.
`static boolean`
`isJava15()`
Always returns true.
`static boolean`
`isJava16()`
Returns true if ImageJ is running on a Java 1.6 or greater JVM.
`static boolean`
`isJava17()`
Returns true if ImageJ is running on a Java 1.7 or greater JVM.
`static boolean`
`isJava18()`
Returns true if ImageJ is running on a Java 1.8 or greater JVM.
`static boolean`
`isJava19()`
Returns true if ImageJ is running on a Java 1.9 or greater JVM.
`static boolean`
`isJava2()`
Always returns true.
`static boolean`
`isLinux()`
Returns true if ImageJ is running on Linux.
`static boolean`
`isMacintosh()`
Returns true if this machine is a Macintosh.
`static boolean`
`isMacOSX()`
Returns true if this machine is a Macintosh running OS X.
`static boolean`
`isMacro()`
Returns true if a macro is running, or if the run(), open() or newImage() method is executing.
`static boolean`
`isResultsWindow()`
Returns true if the "Results" window is open.
`static boolean`
`isVista()`
Obsolete; always returns false.
`static boolean`
`isWindows()`
Returns true if this machine is running Windows.
`static int`
`javaVersion()`
Returns the Java version (6, 7, 8, 9, 10, etc.).
`static void`
`log(String s)`
`static boolean`
`macroRunning()`
Returns true if the run(), open() or newImage() method is executing.
`static void`
`makeLine(double x1, double y1, double x2, double y2)`
Creates a straight line selection using floating point coordinates.
`static void`
`makeLine(int x1, int y1, int x2, int y2)`
Creates a straight line selection.
`static void`
`makeOval(double x, double y, double width, double height)`
Creates an subpixel resolution oval selection.
`static void`
`makeOval(int x, int y, int width, int height)`
Creates an oval selection.
`static void`
`makePoint(double x, double y)`
Creates a point selection using floating point coordinates.
`static void`
`makePoint(int x, int y)`
Creates a point selection using integer coordinates..
`static void`
`makeRectangle(double x, double y, double width, double height)`
Creates a subpixel resolution rectangular selection.
`static void`
`makeRectangle(int x, int y, int width, int height)`
Creates a rectangular selection.
`static long`
`maxMemory()`
Returns the maximum amount of memory available to ImageJ or zero if ImageJ is unable to determine this limit.
`static void`
`newImage(String title, String type, int width, int height, int depth)`
Opens a new image.
`static void`
`noImage()`
Displays a "no images are open" dialog box.
`static void`
`notifyEventListeners(int eventID)`
`static void`
`open()`
Displays a file open dialog box and then opens the tiff, dicom, fits, pgm, jpeg, bmp, gif, lut, roi, or text file selected by the user.
`static void`
`open(String path)`
Opens and displays a tiff, dicom, fits, pgm, jpeg, bmp, gif, lut, roi, or text file.
`static void`
`open(String path, int n)`
Opens and displays the nth image in the specified tiff stack.
`static ByteBuffer`
`openAsByteBuffer(String path)`
`static String`
`openAsString(String path)`
Opens a text file as a string.
`static ImagePlus`
`openImage()`
Opens an image using a file open dialog and returns it as an ImagePlus object.
`static ImagePlus`
`openImage(String path)`
Opens the specified file as a tiff, bmp, dicom, fits, pgm, gif, jpeg or text image and returns an ImagePlus object if successful.
`static ImagePlus`
`openImage(String path, int n)`
Opens the nth image of the specified tiff stack.
`static String`
`openUrlAsString(String url)`
Opens a URL and returns the contents as a string.
`static ImagePlus`
`openVirtual(String path)`
Opens the specified tiff file as a virtual stack.
`static void`
`outOfMemory(String name)`
Displays an "out of memory" message to the "Log" window.
`static OvalRoi`
`OvalRoi(double x, double y, double width, double height)`
Creates an OvalRoi.
`static String`
`pad(int n, int digits)`
Pad 'n' with leading zeros to the specified number of digits.
`static String`
`pad(String s, int digits)`
Pad 's' with leading zeros to the specified number of digits.
`static void`
`protectStatusBar(boolean protect)`
`static void`
`redirectErrorMessages()`
Causes IJ.error() output to be temporarily redirected to the "Log" window.
`static void`
`redirectErrorMessages(boolean redirect)`
Set 'true' and IJ.error() output will be temporarily redirected to the "Log" window.
`static boolean`
`redirectingErrorMessages()`
Returns the state of the 'redirectErrorMessages' flag, which is set by File/Import/Image Sequence.
`static void`
`register(Class c)`
Obsolete
`static void`
`removeEventListener(IJEventListener listener)`
`static void`
`renameResults(String title)`
Renames a results window.
`static void`
`renameResults(String oldTitle, String newTitle)`
Changes the name of a table window from 'oldTitle' to 'newTitle'.
`static void`
`resetClassLoader()`
`static void`
`resetEscape()`
This method sets the `Esc` key to the "up" position.
`static void`
`resetMinAndMax()`
Resets the minimum and maximum displayed pixel values of the current image to be the same as the min and max pixel values.
`static void`
`resetMinAndMax(ImagePlus img)`
Resets the minimum and maximum displayed pixel values of the specified image to be the same as the min and max pixel values.
`static void`
`resetThreshold()`
Disables thresholding on the current image.
`static void`
`resetThreshold(ImagePlus img)`
Disables thresholding on the specified image.
`static Roi`
`Roi(double x, double y, double width, double height)`
Creates an Roi.
`static void`
`run(ImagePlus imp, String command, String options)`
Runs an ImageJ command using the specified image and options.
`static void`
`run(Interpreter interpreter, String command, String options)`
The macro interpreter uses this method to run commands.
`static void`
`run(String command)`
Runs an ImageJ command.
`static void`
`run(String command, String options)`
Runs an ImageJ command, with options that are passed to the GenericDialog and OpenDialog classes.
`static String`
`runMacro(String macro)`
Runs the macro contained in the string `macro` on the current thread.
`static String`
`runMacro(String macro, String arg)`
Runs the macro contained in the string `macro` on the current thread.
`static String`
`runMacroFile(String name)`
Runs the specified macro file.
`static String`
`runMacroFile(String name, String arg)`
Runs the specified macro or script file in the current thread.
`static Object`
`runPlugIn(ImagePlus imp, String className, String arg)`
Runs the specified plugin using the specified image.
`static Object`
`runPlugIn(String className, String arg)`
Runs the specified plugin and returns a reference to it.
`static Object`
`runPlugIn(String commandName, String className, String arg)`
Runs the specified plugin and returns a reference to it.
`static void`
`save(ImagePlus imp, String path)`
Saves the specified image, lookup table or selection to the specified file path.
`static void`
`save(String path)`
Saves the current image, lookup table, selection or text window to the specified file path.
`static void`
`saveAs(ImagePlus imp, String format, String path)`
`static void`
`saveAs(String format, String path)`
`static boolean`
`saveAsTiff(ImagePlus imp, String path)`
Saves the specified image in TIFF format.
`static String`
`saveString(String string, String path)`
Saves a string as a file.
`static void`
`selectWindow(int id)`
For IDs less than zero, activates the image with the specified ID.
`static void`
`selectWindow(String title)`
Activates the window with the specified title.
`static void`
`setAutoThreshold(ImagePlus imp, String method)`
Replaced by ImagePlus.setAutoThreshold().
`static void`
`setBackgroundColor(int red, int green, int blue)`
Sets the background color.
`static void`
`setColumnHeadings(String headings)`
Clears the "Results" window and sets the column headings to those in the tab-delimited 'headings' String.
`static void`
`setDebugMode(boolean b)`
Enable/disable debug mode.
`static void`
`setExceptionHandler(IJ.ExceptionHandler handler)`
Installs a custom exception handler that overrides the handleException() method.
`static void`
`setForegroundColor(int red, int green, int blue)`
Sets the foreground color.
`static void`
`setInputEvent(InputEvent e)`
`static void`
`setKeyDown(int key)`
`static void`
`setKeyUp(int key)`
`static void`
`setMinAndMax(double min, double max)`
Sets the display range (minimum and maximum displayed pixel values) of the current image.
`static void`
`setMinAndMax(double min, double max, int channels)`
Sets the minimum and maximum displayed pixel values on the specified RGB channels, where 4=red, 2=green and 1=blue.
`static void`
`setMinAndMax(ImagePlus img, double min, double max)`
Sets the display range (minimum and maximum displayed pixel values) of the specified image.
`static void`
`setPasteMode(String mode)`
Sets the transfer mode used by the Edit/Paste command, where mode is "Copy", "Blend", "Average", "Difference", "Transparent", "Transparent2", "AND", "OR", "XOR", "Add", "Subtract", "Multiply", or "Divide".
`static void`
`setProperty(String key, Object value)`
Adds a key-value pair to IJ.properties.
`static void`
`setRawThreshold(ImagePlus img, double lowerThreshold, double upperThreshold)`
This is a version of setThreshold() that uses raw (uncalibrated) values in the range 0-255 for 8-bit images and 0-65535 for 16-bit images and the "Red" LUT display mode.
`static void`
`setRawThreshold(ImagePlus img, double lowerThreshold, double upperThreshold, String displayMode)`
This is a version of setThreshold() that always uses raw (uncalibrated) values in the range 0-255 for 8-bit images and 0-65535 for 16-bit images.
`static void`
`setSlice(int slice)`
Switches to the specified stack slice, where 1invalid input: '<'='slice'invalid input: '<'=stack-size.
`static void`
`setTextPanel(TextPanel tp)`
TextWindow calls this method with a null argument when the "Results" window is closed.
`static void`
`setThreshold(double lowerThreshold, double upperThresold)`
Sets the lower and upper threshold levels and displays the image using red to highlight thresholded pixels.
`static void`
`setThreshold(double lowerThreshold, double upperThreshold, String displayMode)`
Sets the lower and upper threshold levels and displays the image using the specified `displayMode` ("Red", "Black invalid input: '&' White", "Over/Under" or "No Update").
`static void`
`setThreshold(ImagePlus img, double lowerThreshold, double upperThreshold)`
Sets the lower and upper threshold levels of the specified image.
`static void`
`setThreshold(ImagePlus img, double lowerThreshold, double upperThreshold, String displayMode)`
Sets the lower and upper threshold levels of the specified image and updates the display using the specified `displayMode` ("Red", "Black invalid input: '&' White", "Over/Under" or "No Update").
`static void`
`setTool(int id)`
Switches to the specified tool, where id = Toolbar.RECTANGLE (0), Toolbar.OVAL (1), etc.
`static boolean`
`setTool(String name)`
Switches to the specified tool, where 'name' is "rect", "elliptical", "brush", etc.
`static int`
`setupDialog(ImagePlus imp, int flags)`
Displays a "Process all images?" dialog.
`static boolean`
`shiftKeyDown()`
Returns true if the shift key is down.
`static void`
`showMessage(String msg)`
Displays a message in a dialog box titled "Message".
`static void`
`showMessage(String title, String msg)`
Displays a message in a dialog box with the specified title.
`static boolean`
`showMessageWithCancel(String title, String msg)`
Displays a message in a dialog box with the specified title.
`static void`
`showProgress(double progress)`
Updates the progress bar, where 0invalid input: '<'=progressinvalid input: '<'=1.0.
`static void`
`showProgress(int currentIndex, int finalIndex)`
Updates the progress bar, where the length of the bar is set to (`currentValue+1)/finalValue` of the maximum bar length.
`static void`
`showStatus(String s)`
Displays a message in the ImageJ status bar.
`static void`
`showStatus(String message, String options)`
Displays a message in the status bar and flashes either the status bar or the active image.
See: http://wsr.imagej.net/macros/FlashingStatusMessages.txt
`static void`
`showTime(ImagePlus imp, long start, String str)`
`static void`
`showTime(ImagePlus imp, long start, String str, int nslices)`
`static boolean`
`spaceBarDown()`
Returns true if the space bar is down.
`static boolean`
`statusBarProtected()`
`static int`
`stringToPasteMode(String mode)`
`static void`
`suppressPluginNotFoundError()`
Temporarily suppress "plugin not found" errors.
`static String`
`time(ImagePlus imp, long startNanoTime)`
Experimental
`static boolean`
`versionLessThan(String version)`
Displays an error message and returns true if the ImageJ version is less than the one specified.
`static void`
`wait(int msecs)`
Delays 'msecs' milliseconds.
`static void`
`write(String s)`
Deprecated.
replaced by IJ.log(), ResultsTable.setResult() and TextWindow.append().

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### font10

public static Font font10
SansSerif, plain, 10-point font

### font12

public static Font font12
SansSerif, plain, 12-point font

### font14

public static Font font14
SansSerif, plain, 14-point font

### COMPOSITE

public static final int COMPOSITE
Image display modes

See Also:
  - Constant Field Values

### COLOR

public static final int COLOR
Image display modes

See Also:
  - Constant Field Values

### GRAYSCALE

public static final int GRAYSCALE
Image display modes

See Also:
  - Constant Field Values

### URL

public static final String URL
Deprecated.

See Also:
  - Constant Field Values

### URL2

public static final String URL2
ImageJ website

See Also:
  - Constant Field Values

### ALL_KEYS

public static final int ALL_KEYS

See Also:
  - Constant Field Values

### debugMode

public static boolean debugMode
Use setDebugMode(boolean) to enable/disable debug mode.

### hideProcessStackDialog

public static boolean hideProcessStackDialog

### micronSymbol

public static final char micronSymbol

See Also:
  - Constant Field Values

### angstromSymbol

public static final char angstromSymbol

See Also:
  - Constant Field Values

### degreeSymbol

public static final char degreeSymbol

See Also:
  - Constant Field Values

### CANCELED

public static final int CANCELED

See Also:
  - Constant Field Values

## Constructor Details

### IJ

public IJ()

## Method Details

### getInstance

public static ImageJ getInstance()
Returns a reference to the "ImageJ" frame.

### setDebugMode

public static void setDebugMode(boolean b)
Enable/disable debug mode.

### runMacro

public static String runMacro(String macro)
Runs the macro contained in the string `macro` on the current thread. Returns any string value returned by the macro, null if the macro does not return a value, or "[aborted]" if the macro was aborted due to an error. The equivalent macro function is eval().

### runMacro

public static String runMacro(String macro, String arg)
Runs the macro contained in the string `macro` on the current thread. The optional string argument can be retrieved in the called macro using the getArgument() macro function. Returns any string value returned by the macro, null if the macro does not return a value, or "[aborted]" if the macro was aborted due to an error.

### runMacroFile

public static String runMacroFile(String name, String arg)
Runs the specified macro or script file in the current thread. The file is assumed to be in the macros folder unless `name` is a full path. The optional string argument (`arg`) can be retrieved in the called macro or script using the getArgument() function. Returns any string value returned by the macro, or null. Scripts always return null. The equivalent macro function is runMacro().

### runMacroFile

public static String runMacroFile(String name)
Runs the specified macro file.

### runPlugIn

public static Object runPlugIn(ImagePlus imp, String className, String arg)
Runs the specified plugin using the specified image.

### runPlugIn

public static Object runPlugIn(String className, String arg)
Runs the specified plugin and returns a reference to it.

### runPlugIn

public static Object runPlugIn(String commandName, String className, String arg)
Runs the specified plugin and returns a reference to it.

### doCommand

public static void doCommand(String command)
Runs a menu command on a separete thread and returns immediately.

### doCommand

public static void doCommand(ImagePlus imp, String command)
Runs a menu command on a separete thread, using the specified image.

### run

public static void run(String command)
Runs an ImageJ command. Does not return until the command has finished executing. To avoid "image locked", errors, plugins that call this method should implement the PlugIn interface instead of PlugInFilter.

### run

public static void run(String command, String options)
Runs an ImageJ command, with options that are passed to the GenericDialog and OpenDialog classes. Does not return until the command has finished executing. To generate run() calls, start the recorder (Plugins/Macro/Record) and run commands from the ImageJ menu bar.

### run

public static void run(Interpreter interpreter, String command, String options)
The macro interpreter uses this method to run commands.

### run

public static void run(ImagePlus imp, String command, String options)
Runs an ImageJ command using the specified image and options. To generate run() calls, start the recorder (Plugins/Macro/Record) and run commands from the ImageJ menu bar.

### macroRunning

public static boolean macroRunning()
Returns true if the run(), open() or newImage() method is executing.

### isMacro

public static boolean isMacro()
Returns true if a macro is running, or if the run(), open() or newImage() method is executing.

### getApplet

public static Applet getApplet()
Returns the Applet that created this ImageJ or null if running as an application.

### showStatus

public static void showStatus(String s)
Displays a message in the ImageJ status bar. If 's' starts with '!', subsequent showStatus() calls in the current thread (without "!" in the message) are suppressed.

### showStatus

public static void showStatus(String message, String options)
Displays a message in the status bar and flashes either the status bar or the active image.
See: http://wsr.imagej.net/macros/FlashingStatusMessages.txt

### write

public static void write(String s)
Deprecated.
replaced by IJ.log(), ResultsTable.setResult() and TextWindow.append(). There are examples at http://imagej.nih.gov/ij/plugins/sine-cosine.html

### log

public static void log(String s)

### getLog

public static String getLog()
Returns the contents of the Log window or null if the Log window is not open.

### setColumnHeadings

public static void setColumnHeadings(String headings)
Clears the "Results" window and sets the column headings to those in the tab-delimited 'headings' String. Writes to System.out.println if the "ImageJ" frame is not present.

### isResultsWindow

public static boolean isResultsWindow()
Returns true if the "Results" window is open.

### renameResults

public static void renameResults(String title)
Renames a results window.

### renameResults

public static void renameResults(String oldTitle, String newTitle)
Changes the name of a table window from 'oldTitle' to 'newTitle'.

### deleteRows

public static void deleteRows(int row1, int row2)
Deletes 'row1' through 'row2' of the "Results" window, where 'row1' and 'row2' must be in the range 0-Analyzer.getCounter()-1.

### getValue

public static double getValue(ImagePlus imp, String measurement)
Returns a measurement result, where 'measurement' is "Area", "Mean", "StdDev", "Mode", "Min", "Max", "X", "Y", "XM", "YM", "Perim.", "BX", "BY", "Width", "Height", "Major", "Minor", "Angle", "Circ.", "Feret", "IntDen", "Median", "Skew", "Kurt", "%Area", "RawIntDen", "Ch", "Slice", "Frame", "FeretX", "FeretY", "FeretAngle", "MinFeret", "AR", "Round", "Solidity", "MinThr" or "MaxThr". Add " raw" to the argument to disable calibration, for example IJ.getValue("Mean raw"). Add " limit" to enable the "limit to threshold" option.

### getTextPanel

public static TextPanel getTextPanel()
Returns a reference to the "Results" window TextPanel. Opens the "Results" window if it is currently not open. Returns null if the "ImageJ" window is not open.

### setTextPanel

public static void setTextPanel(TextPanel tp)
TextWindow calls this method with a null argument when the "Results" window is closed.

### noImage

public static void noImage()
Displays a "no images are open" dialog box.

### outOfMemory

public static void outOfMemory(String name)
Displays an "out of memory" message to the "Log" window.

### showProgress

public static void showProgress(double progress)
Updates the progress bar, where 0invalid input: '<'=progressinvalid input: '<'=1.0. The progress bar is not shown in BatchMode and erased if progress>=1.0. The progress bar is updated only if more than 90 ms have passes since the last call. Does nothing if the ImageJ window is not present.

### showProgress

public static void showProgress(int currentIndex, int finalIndex)
Updates the progress bar, where the length of the bar is set to (`currentValue+1)/finalValue` of the maximum bar length. The bar is erased if `currentValue>=finalValue`. The bar is updated only if more than 90 ms have passed since the last call. Displays subordinate progress bars as dots if 'currentIndex' is negative (example: Plugins/Utilities/Benchmark).

### showMessage

public static void showMessage(String msg)
Displays a message in a dialog box titled "Message". Writes the Java console if ImageJ is not present.

### showMessage

public static void showMessage(String title, String msg)
Displays a message in a dialog box with the specified title. Displays HTML formatted text if 'msg' starts with "
". There are examples at "http://imagej.nih.gov/ij/macros/HtmlDialogDemo.txt". Writes to the Java console if ImageJ is not present.

### error

public static void error(String msg)
Displays a message in a dialog box titled "ImageJ". If a macro or JavaScript is running, it is aborted. Writes to the Java console if the ImageJ window is not present.

### error

public static void error(String title, String msg)
Displays a message in a dialog box with the specified title. If a macro or JavaScript is running, it is aborted. Writes to the Java console if the ImageJ window is not present.

### exit

public static void exit()
Aborts any currently running JavaScript, or use IJ.error(string) to abort a JavaScript with a message.

### getErrorMessage

public static String getErrorMessage()
Returns the last error message written by IJ.error() or null if there was no error since the last time this method was called.

See Also:
  - `error(String)`

### showMessageWithCancel

public static boolean showMessageWithCancel(String title, String msg)
Displays a message in a dialog box with the specified title. Returns false if the user pressed "Cancel".

### getNumber

public static double getNumber(String prompt, double defaultValue)
Allows the user to enter a number in a dialog box. Returns the value IJ.CANCELED (-2,147,483,648) if the user cancels the dialog box. Returns 'defaultValue' if the user enters an invalid number.

### getString

public static String getString(String prompt, String defaultString)
Allows the user to enter a string in a dialog box. Returns "" if the user cancels the dialog box.

### wait

public static void wait(int msecs)
Delays 'msecs' milliseconds.

### beep

public static void beep()
Emits an audio beep.

### freeMemory

public static String freeMemory()
Returns a string something like "64K of 256MB (25%)" that shows how much of the available memory is in use. This is the string displayed when the user clicks in the status bar.

### currentMemory

public static long currentMemory()
Returns the amount of memory currently being used by ImageJ.

### maxMemory

public static long maxMemory()
Returns the maximum amount of memory available to ImageJ or zero if ImageJ is unable to determine this limit.

### showTime

public static void showTime(ImagePlus imp, long start, String str)

### showTime

public static void showTime(ImagePlus imp, long start, String str, int nslices)

### time

public static String time(ImagePlus imp, long startNanoTime)
Experimental

### d2s

public static String d2s(double n)
Converts a number to a formatted string using 2 digits to the right of the decimal point.

### d2s

public static String d2s(double n, int decimalPlaces)
Converts a number to a rounded formatted string. The 'decimalPlaces' argument specifies the number of digits to the right of the decimal point (0-9). Uses scientific notation if 'decimalPlaces is negative.

### d2s

public static String d2s(double x, int significantDigits, int maxDigits)
Converts a number to a rounded formatted string. The 'significantDigits' argument specifies the minimum number of significant digits, which is also the preferred number of digits behind the decimal. Fewer decimals are shown if the number would have more than 'maxDigits'. Exponential notation is used if more than 'maxDigits' would be needed.

### pad

public static String pad(int n, int digits)
Pad 'n' with leading zeros to the specified number of digits.

### pad

public static String pad(String s, int digits)
Pad 's' with leading zeros to the specified number of digits.

### register

public static void register(Class c)
Obsolete

### spaceBarDown

public static boolean spaceBarDown()
Returns true if the space bar is down.

### controlKeyDown

public static boolean controlKeyDown()
Returns true if the control key is down.

### altKeyDown

public static boolean altKeyDown()
Returns true if the alt key is down.

### shiftKeyDown

public static boolean shiftKeyDown()
Returns true if the shift key is down.

### setKeyDown

public static void setKeyDown(int key)

### setKeyUp

public static void setKeyUp(int key)

### setInputEvent

public static void setInputEvent(InputEvent e)

### isMacintosh

public static boolean isMacintosh()
Returns true if this machine is a Macintosh.

### isMacOSX

public static boolean isMacOSX()
Returns true if this machine is a Macintosh running OS X.

### isWindows

public static boolean isWindows()
Returns true if this machine is running Windows.

### javaVersion

public static int javaVersion()
Returns the Java version (6, 7, 8, 9, 10, etc.).

### isJava2

public static boolean isJava2()
Always returns true.

### isJava14

public static boolean isJava14()
Always returns true.

### isJava15

public static boolean isJava15()
Always returns true.

### isJava16

public static boolean isJava16()
Returns true if ImageJ is running on a Java 1.6 or greater JVM.

### isJava17

public static boolean isJava17()
Returns true if ImageJ is running on a Java 1.7 or greater JVM.

### isJava18

public static boolean isJava18()
Returns true if ImageJ is running on a Java 1.8 or greater JVM.

### isJava19

public static boolean isJava19()
Returns true if ImageJ is running on a Java 1.9 or greater JVM.

### isLinux

public static boolean isLinux()
Returns true if ImageJ is running on Linux.

### isVista

public static boolean isVista()
Obsolete; always returns false.

### is64Bit

public static boolean is64Bit()
Returns true if ImageJ is running a 64-bit version of Java.

### versionLessThan

public static boolean versionLessThan(String version)
Displays an error message and returns true if the ImageJ version is less than the one specified.

### setupDialog

public static int setupDialog(ImagePlus imp, int flags)
Displays a "Process all images?" dialog. Returns 'flags'+PlugInFilter.DOES_STACKS if the user selects "Yes", 'flags' if the user selects "No" and PlugInFilter.DONE if the user selects "Cancel".

### makeRectangle

public static void makeRectangle(int x, int y, int width, int height)
Creates a rectangular selection. Removes any existing selection if width or height are less than 1.

### makeRectangle

public static void makeRectangle(double x, double y, double width, double height)
Creates a subpixel resolution rectangular selection.

### makeOval

public static void makeOval(int x, int y, int width, int height)
Creates an oval selection. Removes any existing selection if width or height are less than 1.

### makeOval

public static void makeOval(double x, double y, double width, double height)
Creates an subpixel resolution oval selection.

### makeLine

public static void makeLine(int x1, int y1, int x2, int y2)
Creates a straight line selection.

### makeLine

public static void makeLine(double x1, double y1, double x2, double y2)
Creates a straight line selection using floating point coordinates.

### makePoint

public static void makePoint(int x, int y)
Creates a point selection using integer coordinates..

### makePoint

public static void makePoint(double x, double y)
Creates a point selection using floating point coordinates.

### Roi

public static Roi Roi(double x, double y, double width, double height)
Creates an Roi.

### OvalRoi

public static OvalRoi OvalRoi(double x, double y, double width, double height)
Creates an OvalRoi.

### setMinAndMax

public static void setMinAndMax(double min, double max)
Sets the display range (minimum and maximum displayed pixel values) of the current image.

### setMinAndMax

public static void setMinAndMax(ImagePlus img, double min, double max)
Sets the display range (minimum and maximum displayed pixel values) of the specified image.

### setMinAndMax

public static void setMinAndMax(double min, double max, int channels)
Sets the minimum and maximum displayed pixel values on the specified RGB channels, where 4=red, 2=green and 1=blue.

### resetMinAndMax

public static void resetMinAndMax()
Resets the minimum and maximum displayed pixel values of the current image to be the same as the min and max pixel values.

### resetMinAndMax

public static void resetMinAndMax(ImagePlus img)
Resets the minimum and maximum displayed pixel values of the specified image to be the same as the min and max pixel values.

### setThreshold

public static void setThreshold(double lowerThreshold, double upperThresold)
Sets the lower and upper threshold levels and displays the image using red to highlight thresholded pixels. May not work correctly on 16 and 32 bit images unless the display range has been reset using IJ.resetMinAndMax().

### setThreshold

public static void setThreshold(double lowerThreshold, double upperThreshold, String displayMode)
Sets the lower and upper threshold levels and displays the image using the specified `displayMode` ("Red", "Black invalid input: '&' White", "Over/Under" or "No Update").

### setThreshold

public static void setThreshold(ImagePlus img, double lowerThreshold, double upperThreshold)
Sets the lower and upper threshold levels of the specified image.

### setThreshold

public static void setThreshold(ImagePlus img, double lowerThreshold, double upperThreshold, String displayMode)
Sets the lower and upper threshold levels of the specified image and updates the display using the specified `displayMode` ("Red", "Black invalid input: '&' White", "Over/Under" or "No Update"). With calibrated images, 'lowerThreshold' and 'upperThreshold' must be density calibrated values. Use setRawThreshold() to set the threshold using raw (uncalibrated) values.

### setRawThreshold

public static void setRawThreshold(ImagePlus img, double lowerThreshold, double upperThreshold)
This is a version of setThreshold() that uses raw (uncalibrated) values in the range 0-255 for 8-bit images and 0-65535 for 16-bit images and the "Red" LUT display mode.

### setRawThreshold

public static void setRawThreshold(ImagePlus img, double lowerThreshold, double upperThreshold, String displayMode)
This is a version of setThreshold() that always uses raw (uncalibrated) values in the range 0-255 for 8-bit images and 0-65535 for 16-bit images.

### setAutoThreshold

public static void setAutoThreshold(ImagePlus imp, String method)
Replaced by ImagePlus.setAutoThreshold().

### resetThreshold

public static void resetThreshold()
Disables thresholding on the current image.

### resetThreshold

public static void resetThreshold(ImagePlus img)
Disables thresholding on the specified image.

### selectWindow

public static void selectWindow(int id)
For IDs less than zero, activates the image with the specified ID. For IDs greater than zero, activates the Nth image.

### selectWindow

public static void selectWindow(String title)
Activates the window with the specified title.

### setForegroundColor

public static void setForegroundColor(int red, int green, int blue)
Sets the foreground color.

### setBackgroundColor

public static void setBackgroundColor(int red, int green, int blue)
Sets the background color.

### setTool

public static void setTool(int id)
Switches to the specified tool, where id = Toolbar.RECTANGLE (0), Toolbar.OVAL (1), etc.

### setTool

public static boolean setTool(String name)
Switches to the specified tool, where 'name' is "rect", "elliptical", "brush", etc. Returns 'false' if the name is not recognized.

### getToolName

public static String getToolName()
Returns the name of the current tool.

### doWand

public static int doWand(int x, int y)
Equivalent to clicking on the current image at (x,y) with the wand tool. Returns the number of points in the resulting ROI.

### doWand

public static int doWand(int x, int y, double tolerance, String mode)
Traces the boundary of the area with pixel values within 'tolerance' of the value of the pixel at the starting location. 'tolerance' is in uncalibrated units. 'mode' can be "4-connected", "8-connected" or "Legacy". "Legacy" is for compatibility with previous versions of ImageJ; it is ignored if 'tolerance' > 0.

### doWand

public static int doWand(ImagePlus img, int x, int y, double tolerance, String mode)
This version of doWand adds an ImagePlus argument.

### setPasteMode

public static void setPasteMode(String mode)
Sets the transfer mode used by the Edit/Paste command, where mode is "Copy", "Blend", "Average", "Difference", "Transparent", "Transparent2", "AND", "OR", "XOR", "Add", "Subtract", "Multiply", or "Divide".

### stringToPasteMode

public static int stringToPasteMode(String mode)

### getImage

public static ImagePlus getImage()
Returns a reference to the active image, or displays an error message and aborts the plugin or macro if no images are open.

### getImage

public static ImagePlus getImage(Interpreter interpreter)
The macro interpreter uses this method to call getImage().

### getProcessor

public static ImageProcessor getProcessor()
Returns the active image or stack slice as an ImageProcessor, or displays an error message and aborts the plugin or macro if no images are open.

### setSlice

public static void setSlice(int slice)
Switches to the specified stack slice, where 1invalid input: '<'='slice'invalid input: '<'=stack-size.

### getVersion

public static String getVersion()
Returns the ImageJ version number as a string.

### getFullVersion

public static String getFullVersion()
Returns the ImageJ version and build number as a String, for example "1.46n05", or 1.46n99 if there is no build number.

### getDirectory

public static String getDirectory(String title)
Returns the path to the specified directory if `title` is "home" ("user.home"), "downloads", "startup", "imagej" (ImageJ directory), "plugins", "macros", "luts", "temp", "current", "default", "image" (directory active image was loaded from), "file" (directory most recently used to open or save a file), "cwd" (current working directory) or "preferences" (location of "IJ_Prefs.txt" file), otherwise displays a dialog and returns the path to the directory selected by the user. Returns null if the specified directory is not found or the user cancels the dialog box. Also aborts the macro if the user cancels the dialog box.

### addSeparator

public static String addSeparator(String path)

### getDir

public static String getDir(String title)
Alias for getDirectory().

### getFilePath

public static String getFilePath(String dialogTitle)
Displays an open file dialog and returns the path to the choosen file, or returns null if the dialog is canceled.

### open

public static void open()
Displays a file open dialog box and then opens the tiff, dicom, fits, pgm, jpeg, bmp, gif, lut, roi, or text file selected by the user. Displays an error message if the selected file is not in one of the supported formats, or if it is not found.

### open

public static void open(String path)
Opens and displays a tiff, dicom, fits, pgm, jpeg, bmp, gif, lut, roi, or text file. Displays an error message if the specified file is not in one of the supported formats, or if it is not found. With 1.41k or later, opens images specified by a URL.

### open

public static void open(String path, int n)
Opens and displays the nth image in the specified tiff stack.

### openImage

public static ImagePlus openImage(String path)
Opens the specified file as a tiff, bmp, dicom, fits, pgm, gif, jpeg or text image and returns an ImagePlus object if successful. Calls HandleExtraFileTypes plugin if the file type is not recognised. Displays a file open dialog if 'path' is null or an empty string. Note that 'path' can also be a URL. Some reader plugins, including the Bio-Formats plugin, display the image and return null. Use IJ.open() to display a file open dialog box.

See Also:
  - `Opener.openUsingBioFormats(String)`

### openImage

public static ImagePlus openImage(String path, int n)
Opens the nth image of the specified tiff stack.

### openVirtual

public static ImagePlus openVirtual(String path)
Opens the specified tiff file as a virtual stack.

### openImage

public static ImagePlus openImage()
Opens an image using a file open dialog and returns it as an ImagePlus object.

### openUrlAsString

public static String openUrlAsString(String url)
Opens a URL and returns the contents as a string. Returns "invalid input: '<'Error: message>" if there an error, including host or file not found.

### save

public static void save(String path)
Saves the current image, lookup table, selection or text window to the specified file path. The path must end in ".tif", ".jpg", ".gif", ".zip", ".raw", ".avi", ".bmp", ".fits", ".pgm", ".png", ".lut", ".roi" or ".txt".

### save

public static void save(ImagePlus imp, String path)
Saves the specified image, lookup table or selection to the specified file path. The file path should end with ".tif", ".jpg", ".gif", ".zip", ".raw", ".avi", ".bmp", ".fits", ".pgm", ".png", ".lut", ".roi" or ".txt". The specified image is saved in TIFF format if there is no extension.

### saveAs

public static void saveAs(String format, String path)

### saveAs

public static void saveAs(ImagePlus imp, String format, String path)

### saveAsTiff

public static boolean saveAsTiff(ImagePlus imp, String path)
Saves the specified image in TIFF format. Displays a file save dialog if 'path' is null or an empty string. Returns 'false' if there is an error or if the user selects "Cancel" in the file save dialog.

### saveString

public static String saveString(String string, String path)
Saves a string as a file. Displays a file save dialog if 'path' is null or blank. Returns an error message if there is an exception, otherwise returns null.

### append

public static String append(String string, String path)
Appends a string to the end of a file. A newline character ("\n") is added to the end of the string before it is written. Returns an error message if there is an exception, otherwise returns null.

### openAsString

public static String openAsString(String path)
Opens a text file as a string. Displays a file open dialog if path is null or blank. Returns null if the user cancels the file open dialog. If there is an error, returns a message in the form "Error: message".

### openAsByteBuffer

public static ByteBuffer openAsByteBuffer(String path)

### createImage

public static ImagePlus createImage(String title, int width, int height, int depth, int bitdepth)
Creates a new image.

Parameters:
  `title` - image name
  `width` - image width in pixels
  `height` - image height in pixels
  `depth` - number of stack images
  `bitdepth` - 8, 16, 32 (float) or 24 (RGB)

### createImage

public static ImagePlus createImage(String title, String type, int width, int height, int depth)
Creates a new imagePlus. `Type` should contain "8-bit", "16-bit", "32-bit" or "RGB". In addition, it can contain "white", "black" or "ramp". `Width` and `height` specify the width and height of the image in pixels. `Depth` specifies the number of stack slices.

### createImage

public static ImagePlus createImage(String title, String type, int width, int height, int channels, int slices, int frames)
Creates a new hyperstack.

Parameters:
  `title` - image name
  `type` - "8-bit", "16-bit", "32-bit" or "RGB". May also contain "white" , "black" (the default), "ramp", "composite-mode", "color-mode", "grayscale-mode or "label".
  `width` - image width in pixels
  `height` - image height in pixels
  `channels` - number of channels
  `slices` - number of slices
  `frames` - number of frames

### createHyperStack

public static ImagePlus createHyperStack(String title, int width, int height, int channels, int slices, int frames, int bitdepth)
Creates a new hyperstack.

Parameters:
  `title` - image name
  `width` - image width in pixels
  `height` - image height in pixels
  `channels` - number of channels
  `slices` - number of slices
  `frames` - number of frames
  `bitdepth` - 8, 16, 32 (float) or 24 (RGB)

### newImage

public static void newImage(String title, String type, int width, int height, int depth)
Opens a new image. `Type` should contain "8-bit", "16-bit", "32-bit" or "RGB". In addition, it can contain "white", "black" or "ramp". `Width` and `height` specify the width and height of the image in pixels. `Depth` specifies the number of stack slices.

### escapePressed

public static boolean escapePressed()
Returns true if the `Esc` key was pressed since the last ImageJ command started to execute or since resetEscape() was called.

### resetEscape

public static void resetEscape()
This method sets the `Esc` key to the "up" position. The Executer class calls this method when it runs an ImageJ command in a separate thread.

### redirectErrorMessages

public static void redirectErrorMessages()
Causes IJ.error() output to be temporarily redirected to the "Log" window.

### redirectErrorMessages

public static void redirectErrorMessages(boolean redirect)
Set 'true' and IJ.error() output will be temporarily redirected to the "Log" window.

### redirectingErrorMessages

public static boolean redirectingErrorMessages()
Returns the state of the 'redirectErrorMessages' flag, which is set by File/Import/Image Sequence.

### suppressPluginNotFoundError

public static void suppressPluginNotFoundError()
Temporarily suppress "plugin not found" errors.

### getClassLoader

public static ClassLoader getClassLoader()
Returns the class loader ImageJ uses to run plugins or the system class loader if Menus.getPlugInsPath() returns null.

### getScreenSize

public static Dimension getScreenSize()
Returns the size, in pixels, of the primary display.

### getLuts

public static String[] getLuts()
Returns, as an array of strings, a list of the LUTs in the Image/Lookup Tables menu.

See Also:
  - `See also: Help>Examples>JavaScript/Show all LUTs and Image/Color/Display LUTs`

### resetClassLoader

public static void resetClassLoader()

### handleException

public static void handleException(Throwable e)
Displays a stack trace. Use the setExceptionHandler method() to override with a custom exception handler.

### setExceptionHandler

public static void setExceptionHandler(IJ.ExceptionHandler handler)
Installs a custom exception handler that overrides the handleException() method.

### addEventListener

public static void addEventListener(IJEventListener listener)

### removeEventListener

public static void removeEventListener(IJEventListener listener)

### notifyEventListeners

public static void notifyEventListeners(int eventID)

### setProperty

public static void setProperty(String key, Object value)
Adds a key-value pair to IJ.properties. The key and value are removed if 'value' is null.

### getProperty

public static Object getProperty(String key)
Returns the object in IJ.properties associated with 'key', or null if 'key' is not found.

### statusBarProtected

public static boolean statusBarProtected()

### protectStatusBar

public static void protectStatusBar(boolean protect)