ij
Class IJ

java.lang.Object
  extended by ij.IJ

public class IJ
extends java.lang.Object

This class consists of static utility methods.


Field Summary
static int ALL_KEYS
           
static char angstromSymbol
           
static int CANCELED
           
static boolean debugMode
           
static char degreeSymbol
           
static boolean hideProcessStackDialog
           
static char micronSymbol
           
 
Constructor Summary
IJ()
           
 
Method Summary
static boolean altKeyDown()
          Returns true if the alt key is down.
static void beep()
          Emits an audio beep.
static ImagePlus createImage(java.lang.String title, java.lang.String type, int width, int height, int depth)
          Creates a new imagePlus.
static long currentMemory()
          Returns the amount of memory currently being used by ImageJ.
static java.lang.String d2s(double n)
          Converts a number to a formatted string using 2 digits to the right of the decimal point.
static java.lang.String d2s(double n, int decimalPlaces)
          Converts a number to a rounded formatted string.
static void doCommand(java.lang.String command)
          Starts executing a menu command in 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 void error(java.lang.String msg)
          Displays a message in a dialog box titled "ImageJ".
static void error(java.lang.String title, java.lang.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 java.lang.String freeMemory()
          Runs the garbage collector and returns a string something like "64K of 256MB (25%)" that shows how much of the available memory is in use.
static java.applet.Applet getApplet()
          Returns the Applet that created this ImageJ or null if running as an application.
static java.lang.ClassLoader getClassLoader()
          Returns an instance of the class loader ImageJ uses to run plugins.
static java.lang.String getDirectory(java.lang.String title)
          Returns the path to the home ("user.home"), startup (ImageJ directory), plugins, macros, temp, current or image directory if title is "home", "startup", "plugins", "macros", "temp", "current" or "image", otherwise, displays a dialog and returns the path to the directory selected by the user.
static ImagePlus getImage()
          Returns a reference to the active image.
static ImageJ getInstance()
          Returns a reference to the "ImageJ" frame.
static double getNumber(java.lang.String prompt, double defaultValue)
          Allows the user to enter a number in a dialog box.
static java.lang.String getString(java.lang.String prompt, java.lang.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 java.lang.String getVersion()
          Returns the ImageJ version number as a string.
static boolean isJava14()
          Returns true if ImageJ is running on a Java 1.4 or greater JVM.
static boolean isJava15()
          Returns true if ImageJ is running on a Java 1.5 or greater JVM.
static boolean isJava16()
          Returns true if ImageJ is running on a Java 1.6 or greater JVM.
static boolean isJava2()
          Returns true if ImageJ is running on Java 2.
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 isResultsWindow()
          Returns true if the "Results" window is open.
static boolean isVista()
          Returns true if ImageJ is running on Windows Vista.
static boolean isWindows()
          Returns true if this machine is running Windows.
static void log(java.lang.String s)
           
static boolean macroRunning()
          Returns true if either of the IJ.run() methods is executing.
static void makeLine(int x1, int y1, int x2, int y2)
          Creates a straight line selection.
static void makeOval(int x, int y, int width, int height)
          Creates an elliptical 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(java.lang.String title, java.lang.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 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(java.lang.String path)
          Opens and displays a tiff, dicom, fits, pgm, jpeg, bmp, gif, lut, roi, or text file.
static ImagePlus openImage(java.lang.String path)
          Open the specified file as a tiff, bmp, dicom, fits, pgm, gif or jpeg image and returns an ImagePlus object if successful.
static void outOfMemory(java.lang.String name)
          Displays an "out of memory" message to the "Log" window.
static void redirectErrorMessages()
          Causes IJ.error() and IJ.showMessage() output to be temporarily redirected to the "Log" window.
static boolean redirectingErrorMessages()
          Returns the state of the 'redirectErrorMessages' flag.
static void register(java.lang.Class c)
          Adds the specified class to a Vector to keep it from being garbage collected, which would cause the classes static fields to be reset.
static void resetEscape()
          This method sets the Esc key to the "up" position.
static void resetMinAndMax()
          Resets the minimum and maximum displayed pixel values to be the same as the min and max pixel values.
static void resetThreshold()
          Disables thresholding.
static void run(java.lang.String command)
          Runs an ImageJ command.
static void run(java.lang.String command, java.lang.String options)
          Runs an ImageJ command, with options that are passed to the GenericDialog and OpenDialog classes.
static java.lang.String runMacro(java.lang.String macro)
          Runs the macro contained in the string macro.
static java.lang.String runMacro(java.lang.String macro, java.lang.String arg)
          Runs the macro contained in the string macro.
static java.lang.String runMacroFile(java.lang.String name)
          Runs the specified macro file.
static java.lang.String runMacroFile(java.lang.String name, java.lang.String arg)
          Runs the specified macro file.
static java.lang.Object runPlugIn(java.lang.String className, java.lang.String arg)
          Runs the specified plugin and returns a reference to it.
static void save(java.lang.String path)
          Saves an image, lookup table, selection or text window to the specified file path.
static void saveAs(java.lang.String format, java.lang.String path)
           
static void selectWindow(int id)
          For IDs less than zero, activates the image with the specified ID.
static void selectWindow(java.lang.String title)
          Activates the window with the specified title.
static void setBackgroundColor(int red, int green, int blue)
          Sets the background color.
static void setColumnHeadings(java.lang.String headings)
          Clears the "Results" window and sets the column headings to those in the tab-delimited 'headings' String.
static void setForegroundColor(int red, int green, int blue)
          Sets the foreground color.
static void setInputEvent(java.awt.event.InputEvent e)
           
static void setKeyDown(int key)
           
static void setKeyUp(int key)
           
static void setMinAndMax(double min, double max)
          Sets the minimum and maximum displayed pixel values.
static void setPasteMode(java.lang.String mode)
          Sets the transfer mode used by the Edit/Paste command, where mode is "Copy", "Blend", "Average", "Difference", "Transparent", "AND", "OR", "XOR", "Add", "Subtract", "Multiply", or "Divide".
static void setSlice(int slice)
          Switches to the specified stack slice, where 1<='slice'<=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, java.lang.String displayMode)
          Sets the lower and upper threshold levels and displays the image using the specified displayMode ("Red", "Black & 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 int setupDialog(ImagePlus imp, int flags)
          Displays a "Process all slices?" dialog.
static boolean shiftKeyDown()
          Returns true if the shift key is down.
static void showMessage(java.lang.String msg)
          Displays a message in a dialog box titled "Message".
static void showMessage(java.lang.String title, java.lang.String msg)
          Displays a message in a dialog box with the specified title.
static boolean showMessageWithCancel(java.lang.String title, java.lang.String msg)
          Displays a message in a dialog box with the specified title.
static void showProgress(double progress)
          Updates the progress bar, where 0<=progress<=1.0.
static void showProgress(int currentIndex, int finalIndex)
          Updates the progress bar, where bar-length = (currentIndex/finalIndex)*total-length.
static void showStatus(java.lang.String s)
          Displays a message in the ImageJ status bar.
static void showTime(ImagePlus imp, long start, java.lang.String str)
           
static boolean spaceBarDown()
          Returns true if the space bar is down.
static void suppressPluginNotFoundError()
          Temporarily suppress "plugin not found" errors.
static boolean versionLessThan(java.lang.String version)
          Displays an error message and returns false if the ImageJ version is less than the one specified.
static void wait(int msecs)
          Delays 'msecs' milliseconds.
static void write(java.lang.String s)
          Displays a line of text in the "Results" window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALL_KEYS

public static final int ALL_KEYS
See Also:
Constant Field Values

debugMode

public static boolean debugMode

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 Detail

IJ

public IJ()
Method Detail

getInstance

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


runMacro

public static java.lang.String runMacro(java.lang.String macro)
Runs the macro contained in the string macro. Returns any string value returned by the macro, or null. The equivalent macro function is eval().


runMacro

public static java.lang.String runMacro(java.lang.String macro,
                                        java.lang.String arg)
Runs the macro contained in the string macro. The optional string argument can be retrieved in the called macro using the getArgument() macro function. Returns any string value returned by the macro, or null.


runMacroFile

public static java.lang.String runMacroFile(java.lang.String name,
                                            java.lang.String arg)
Runs the specified macro file. The file is assumed to be in the macros folder unless name is a full path. ".txt" is added if name does not have an extension. The optional string argument (arg) can be retrieved in the called macro using the getArgument() macro function. Returns any string value returned by the macro or null. The equivalent macro function is runMacro().


runMacroFile

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


runPlugIn

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


doCommand

public static void doCommand(java.lang.String command)
Starts executing a menu command in a separete thread and returns immediately.


run

public static void run(java.lang.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(java.lang.String command,
                       java.lang.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.


macroRunning

public static boolean macroRunning()
Returns true if either of the IJ.run() methods is executing.


getApplet

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


showStatus

public static void showStatus(java.lang.String s)
Displays a message in the ImageJ status bar.


write

public static void write(java.lang.String s)
Displays a line of text in the "Results" window. Writes to System.out.println if the "ImageJ" frame is not present.


log

public static void log(java.lang.String s)

setColumnHeadings

public static void setColumnHeadings(java.lang.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.


getTextPanel

public static TextPanel getTextPanel()
Returns a reference to the "Results" window TextPanel. Opens the "Results" window if it is currently 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(java.lang.String name)
Displays an "out of memory" message to the "Log" window.


showProgress

public static void showProgress(double progress)
Updates the progress bar, where 0<=progress<=1.0. The progress bar is not displayed if the time between the first and second calls to this method is less than 30 milliseconds. It is erased if progress>=1.0. Does nothing if the ImageJ window is not present.


showProgress

public static void showProgress(int currentIndex,
                                int finalIndex)
Updates the progress bar, where bar-length = (currentIndex/finalIndex)*total-length. The bar is erased if currentIndex>=finalIndex. Does nothing if the ImageJ window is not present.


showMessage

public static void showMessage(java.lang.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(java.lang.String title,
                               java.lang.String msg)
Displays a message in a dialog box with the specified title. Writes the Java console if ImageJ is not present.


error

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


error

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


showMessageWithCancel

public static boolean showMessageWithCancel(java.lang.String title,
                                            java.lang.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(java.lang.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 java.lang.String getString(java.lang.String prompt,
                                         java.lang.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 java.lang.String freeMemory()
Runs the garbage collector and 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,
                            java.lang.String str)

d2s

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


d2s

public static java.lang.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).


register

public static void register(java.lang.Class c)
Adds the specified class to a Vector to keep it from being garbage collected, which would cause the classes static fields to be reset. Probably not needed with Java 1.2 or later.


spaceBarDown

public static boolean spaceBarDown()
Returns true if the space bar 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(java.awt.event.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.


isJava2

public static boolean isJava2()
Returns true if ImageJ is running on Java 2.


isJava14

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


isJava15

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


isJava16

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


isLinux

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


isVista

public static boolean isVista()
Returns true if ImageJ is running on Windows Vista.


versionLessThan

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


setupDialog

public static int setupDialog(ImagePlus imp,
                              int flags)
Displays a "Process all slices?" 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.


makeOval

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


makeLine

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


setMinAndMax

public static void setMinAndMax(double min,
                                double max)
Sets the minimum and maximum displayed pixel values.


resetMinAndMax

public static void resetMinAndMax()
Resets the minimum and maximum displayed pixel values 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,
                                java.lang.String displayMode)
Sets the lower and upper threshold levels and displays the image using the specified displayMode ("Red", "Black & White", "Over/Under" or "No Update").


resetThreshold

public static void resetThreshold()
Disables thresholding.


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(java.lang.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.


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.


setPasteMode

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


getImage

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


setSlice

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


getVersion

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


getDirectory

public static java.lang.String getDirectory(java.lang.String title)
Returns the path to the home ("user.home"), startup (ImageJ directory), plugins, macros, temp, current or image directory if title is "home", "startup", "plugins", "macros", "temp", "current" or "image", 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.


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(java.lang.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.


openImage

public static ImagePlus openImage(java.lang.String path)
Open the specified file as a tiff, bmp, dicom, fits, pgm, gif or jpeg image and returns an ImagePlus object if successful. Calls HandleExtraFileTypes plugin if the file type is not recognised. Note that 'path' can also be a URL.


save

public static void save(java.lang.String path)
Saves an 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".


saveAs

public static void saveAs(java.lang.String format,
                          java.lang.String path)

createImage

public static ImagePlus createImage(java.lang.String title,
                                    java.lang.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" (the default is "white"). Width and height specify the width and height of the image in pixels. Depth specifies the number of stack slices.


newImage

public static void newImage(java.lang.String title,
                            java.lang.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" (the default is "white"). 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() and IJ.showMessage() output to be temporarily redirected to the "Log" window.


redirectingErrorMessages

public static boolean redirectingErrorMessages()
Returns the state of the 'redirectErrorMessages' flag. The File/Import/Image Sequence command sets this flag.


suppressPluginNotFoundError

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


getClassLoader

public static java.lang.ClassLoader getClassLoader()
Returns an instance of the class loader ImageJ uses to run plugins.