abs(n)
Returns the absolute value of n.atan(angle)
Calculates the inverse tangent (arc tangent) of an angle in radians. Returns a value in the range -pi/2 through pi/2.autoUpdate(boolean)
If boolean is true, the display is refreshed each time lineTo(), drawLine(), drawString(), etc. are called, otherwise, the display is refreshed only when updateDisplay() is called or when the macro terminates.beep()
Emits an audible beep.bitDepth()
Returns the bit depth of the active image: 8, 16, 24 (RGB) or 32 (float).changeValues(v1, v2, v3)
Changes pixels in the image or selection that have a value in the range v1-v2 to v3. For example, changeValues(0,5,5) changes all pixels less than 5 to 5, and changeValues(0x0000ff,0x0000ff,0xff0000) changes all blue pixels in an RGB image to red.charCodeAt(string, index)
Returns the Unicode value of the character at the specified index in string. Index values can range from 0 to lengthOf(string). Use the fromCharCode() function to convert one or more Unicode characters to a string.close()
Closes the active image. Unlike run("Close"), this function works when the macro is in batch mode. It also has the advantage of not closing the "Log" or "Results" window when you meant to close the active image. Requires 1.33n.cos(angle)
Returns the cosine of an angle (in radians).d2s()
This function will probably be replaced by one with a better name.doCommand("Command")
Runs an ImageJ menu command in a separate thread and returns immediately. As an example, "doCommand('Start Animation [=]')" starts animating the current stack in a separate thread and the macro continues to execute. Use "run(doCommand('Start Animation [=]')" and the macro hangs until the user stops the animation.doWand(x, y)
Equivalent to clicking on the current image at (x,y) with the wand tool.drawLine(x1, y1, x2, y2)
Draws a line between (x1, y1) and (x2, y2). Use setColor() to specify the color of the line and setLineWidth() to vary the line width.drawString("text", x, y)
Draws text at the specified location. Call setFont() to specify the font. Call setJustification() to have the text centered or right justified. Refer to the TextDemo macro for examples.dump()
Writes the contents of the symbol table, the tokenized macro code and the variable stack to the "Log" window.endsWith(string, suffix)
Returns true (1) if string ends with suffix. See also: startsWith, indexOf, substring. Requires v1.32f.exit(["error message"])
Terminates execution of the macro and, optionally, displays an error message.exp()
Returns the exponential number e (i.e., 2.718...) raised to the power of n.fill()
Fills the image or selection with the current drawing color.floor(n)
Returns the largest value that is not greater than n and is equal to an integer.fromCharCode(value1,...,valueN)
This function takes one or more Unicode values and returns a string.getArgument()
Returns the string argument passed to macros called by IJ.runMacro(macro, arg) or IJ.runMacroFile(path, arg). Requires v1.33c.getBoolean("message")
Displays a dialog box containing the specified message and "Yes", "No" and "Cancel" buttons. Returns true (1) if the user clicks "Yes", returns false (0) if the user clicks "No" and exits the macro if the user clicks "Cancel". Requires v1.31p.getBoundingRect(x, y, width, height)
Returns the smallest rectangle that can completely contain the current selection. x and y are the pixel coordinates of the upper left corner of the rectangle. width and height are the width and height of the rectangle in pixels. If there is no selection, returns (0, 0, ImageWidth, ImageHeight).getCursorLoc(x, y, z, modifiers)
Returns the cursor location in pixels and the mouse event modifier flags. The z coordinate is zero for 2D images. For stacks, it is one less than the slice number. For an example, see the GetCursorLocDemo macro.getDirectory(title)
Iftitle
is "plugins", "macros", "temp" or "image", returns the path to the plugins folder, macros folder, temp folder or the folder that the active image was loaded from. Otherwise, displays a dialog and returns the path to the directory selected by the user. Returns an empty string if the specified directory is not found or aborts the macro if the user cancels the dialog box. For an example, see the ListFilesRecursively macro. Requires v1.32f or later.getFileList(directory)
Returns an array containing the names of the files in the specified directory path. The names of subdirectories have a "/" appended. For an example, see the ListFilesRecursively macro. Requires v1.32f or later.getImageID()
Returns the unique ID (a negative number) of the active image. Use the selectImage(id), isOpen(id) and isActive(id) functions to activate an image or to determine if it is open or active.getInfo()
If the front window is an image, returns a string containing the text that would be displayed by Image/Show Info for that image. If the front window is a text window, returns the contents of that window. Use split(getInfo(),'\n') to break the string returned by this function into separate lines.getLine(x1, y1, x2, y2, lineWidth)
Returns the starting coordinates, ending coordinates and width of the current straight line selection. Sets x1 = -1 if there is no line selection.getHeight()
Returns the height in pixels of the current image.getHistogram(values, counts, nBins)
Returns the histogram of the current image or selection. Values is an array that will contain the pixel values for each of the histogram counts, or set this argument to 0. Counts is an array that will contain the histogram counts. nBins is the number of bins that will be used. It must be 256 for 8 bit and RGB image, 256 or 65536 for 16 bit images, or an integer greater than zero for 32 bit images. The Values argument is ignored if nBins is 65536.getLut(reds, greens, blues)
Returns three arrays containing the red, green and blue intensity values from the current lookup table. See the LookupTables macros for examples.getMinAndMax(min, max)
Returns the minimum and maximum displayed pixel values (display range). See the DisplayRangeMacros for examples. Requires v1.33k.getNumber("prompt", defaultValue)
Displays a dialog box and returns the number entered by the user. The first argument is the prompting message and the second is the value initially displayed in the dialog. Exits the macro if the user clicks on "Cancel" in the dialog. Returns defaultValue if the user enters an invalid number.getPixel(x, y)
Returns the value of the pixel at (x,y). Note that pixels in RGB images contain red, green and blue components that need to be extracted using shifting and masking. See the Color Picker Tool macro for an example that show how to do this.getPixelSize(unit, pixelWidth, pixelHeight[, pixelDepth])
Returns the unit of length (as a string) and the pixel dimensions. For an example, see the ShowImageInfo macro. Requires v1.32f or later.getProfile()
Runs Analyze/Plot Profile (without displaying the plot) and returns the intensity values as an array. For an example, see the GetProfileExample macro.getResult("Column", row)
Returns a measurement from the ImageJ results table. The first argument specifies a column in the table. It must be a "Results" window column label, such as "Area", "Mean" or "Circ.". The second argument specifies the row, where 0<=row<nResults. nResults is a predefined variable that contains the current measurement count. (Actually, it's a built-in function with the "()" optional.)getSelectionCoordinates(xCoordinates, yCoordinates)
Returns two arrays containing the X and Y coordinates of the points that define the current selection. See the SelectionCoordinates macro for an example.getString("prompt", "default")
Displays a dialog box and returns the string entered by the user. The first argument is the prompting message and the second is the initial string value. Exits the macro if the user clicks on "Cancel" or enters an empty string.getThreshold(lower, upper)
Returns the lower and upper threshold levels. Both variables are set to -1 if the active image is not thresholded. Requires v1.32e.getTime()
Returns the current time in milliseconds. The granularity of the time varies considerably from one platform to the next. On Windows NT, 2K, XP it is about 10ms. On other Windows versions it can be as poor as 50ms. On many Unix platforms, including Mac OS X, it actually is 1ms.getTitle()
Returns the title of the current image.getVoxelSize(width, height, depth, unit)
Returns the voxel size and unit of length ("pixel", "mm", etc.) of the current image or stack.getWidth()
Returns the width in pixels of the current image.indexOf(string, substring)
Returns the index within string of the first occurrence of substring. See also: lastIndexOf, startsWith, endsWith, substring.indexOf(string, substring, fromIndex)
Returns the index within string of the first occurrence of substring, with the search starting at fromIndex.isActive(id)
Returns true if the image with the specified ID is active.isOpen(id)
Returns true if the image with the specified ID is open.isOpen("Title")
Returns true if the window with the specified title is open. Requires v1.31m.lastIndexOf(string, substring)
Returns the index within string of the rightmost occurrence of substring. See also: indexOf, startsWith, endsWith, substring.lengthOf(str)
Returns the length of a string or array.lineTo(x, y)
Draws a line from current location to (x,y) .log(n)
Returns the natural logarithm (base e) of n.makeLine(x1, y1, x2, y2)
Creates a new straight line selection. The origin (0,0) is assumed to be the upper left corner of the image. Coordinates are in pixels.makeOval(x, y, width, height)
Creates an elliptical selection, where (x,y) define the upper left corner of the bounding rectangle of the ellipse.makeRectangle(x, y, width, height)
Creates a rectangular selection. The x and y arguments are the coordinates (in pixels) of the upper left corner of the selection. The origin (0,0) of the coordinate system is the upper left corner of the image.makeSelection(type, xcoord, ycoord)
Creates a selection from a list of XY coordinates. The first argument should be "polygon", "freehand", "polyline", "freeline", "angle" or "point". In ImageJ 1.32g or later, it can also be the numeric value returned by selectionType. The xcoord and ycoord arguments are numeric arrays that contain the X and Y coordinates. See the MakeSelectionDemo macro for examples. Requires v1.31b. The "point" type requires v1.33g.maxOf(n1, n2)
Returns the greater of two values.minOf(n1, n2)
Returns the smaller of two values.moveTo(x, y)
Sets the current drawing location. The origin is always assumed to be the upper left corner of the image.newArray(size)
Returns a new array containing size elements. Array elements can be numbers or strings. For an example, see the Arrays macro.nImages
Returns number of open images. The parentheses "()" are optional.nResults
Returns the current measurement counter value. The parentheses "()" are optional.nSlices
Returns number of slices in current stack. The parentheses "()" are optional.open(path)
Opens and displays a tiff, dicom, fits, pgm, jpeg, bmp, gif, lut, roi, or text file. Displays an error message and aborts the macro if the specified file is not in one of the supported formats, or if the file is not found. Displays a file open dialog box if path is an empty string or if there is no argument. Use the File/Open command with the command recorder running to generate calls to this function. Requires ImageJ 1.33d.Plot.create("Title", "X-axis Label", "Y-axis Label", xValues, yValues)
Generates a plot using the specified title, axis labels and X and Y coordinate arrays. If only one array is specified it is assumed to contain the Y values and a 0..n-1 sequence is used as the X values. It is also permissible to specify no arrays and use Plot.setLimits() and Plot.add() to generate the plot. Use Plot.show() to display the plot in a window or it will be displayed automatically when the macro exits. For examples, check out the ExamplePlots macro file. Requires v1.31k or later.Plot.setLimits(xMin, xMax, yMin, yMax)
Sets the range of the x-axis and y-axis of plots created using Plot.create().Plot.setLineWidth(width)
Specifies the width of the line used to draw a curve. Points (circle, box, etc.) are also drawn larger if a line width greater than one is specified. Note that the curve specified in Plot.create() is the last one drawn before the plot is dispayed or updated.Plot.setColor("red")
Specifies the color used in subsequent calls to Plot.add() or Plot.addText(). The argument can be "black", "blue", "cyan", "darkGray", "gray", "green", "lightGray", "magenta", "orange", "pink", "red", "white" or "yellow". Note that the curve specified in Plot.create() is drawn last. Requires v1.31l or later.Plot.add("circles", xValues, yValues)
Adds a curve, set of points or error bars to a plot created using Plot.create(). If only one array is specified it is assumed to contain the Y values and a 0..n-1 sequence is used as the X values. The first argument can be "line", "circles", "boxes", "triangles", "crosses", "dots", "x" or "error bars".Plot.addText("A line of text", x, y)
Adds text to the plot at the specified location, where (0,0) is the upper left corner of the the plot frame and (1,1) is the lower right corner. Call Plot.setJustification() to have the text centered or right justified. Requires v1.31l or later.Plot.setJustification("center")
Specifies the justification used by Plot.addText(). The argument can be "left", "right" or "center". The default is "left". Requires v1.31l or later.Plot.show()
Displays the plot generated by Plot.create(), Plot.add(), etc. in a window. This function is automatically called when a macro exits.Plot.update()
Draws the plot generated by Plot.create(), Plot.add(), etc. in an existing plot window. Equivalent to Plot.show() if no plot window is open.pow(base, exponent)
Returns the value of base raised to the power of exponent.print(string)
Outputs a string to the "Log" window. Numeric arguments are automatically converted to strings. Refer to the SineCosineTable macro for an example of how to save the contents of the "Log" window to a text file.random()
Returns a random number between 0 and 1.requires("1.29p")
Display a message and aborts the macro if the ImageJ version is less than the one specified.reset()
Restores the backup image created by snapshot().resetMinAndMax()
Resets the minimum and maximum displayed pixel values (display range) to be the same as the current image's minimum and maximum pixel values. See the DisplayRangeMacros for examples.resetThreshold()
Disables thresholding.restoreSettings()
Restores Edit/Options submenu settings saved by the saveSettings() function. Requires v1.33a.roiManager(cmd)
Runs an ROI Manager command, where cmd must be "Add", "Add & Draw", "Measure", "Draw" or "Combine". The ROI Manager is opened if it is not already open. Requires v1.33f.roiManager(cmd, path)
Runs an ROI Manager I/O command, where cmd is "Open" or "Save and path is a file path. The ROI Manager is opened if it is not already open. Requires v1.33j.round(n)
Returns the closest integer to n.run("command"[, "options"])
Executes an ImageJ menu command. The optional second argument contains values that are automatically entered into dialog boxes (must be GenericDialog or OpenDialog). Use the Command Recorder (Plugins/Macros/Record) to generate run() function calls. Use string concatentation to pass a variable as an argument. For examples, see the ArgumentPassingDemo macro.saveSettings()
Saves most Edit/Options submenu settings so they can be restored later by calling restoreSettings(). Requires v1.33a.selectionType()
Returns the selection type, where 0=rectangle, 1=oval, 2=polygon, 3=freehand, 4=traced, 5=straight line, 6=segmented line, 7=freehand line, 8=angle, 9=composite and 10=point. Returns -1 if there is no selection. For an example, see the ShowImageInfo macro.selectImage(id)
Activates the image with the specified ID (a negative number). If id is greater than one, activates the idth image listed in the Window menu. With ImageJ 1.33n and later, id can be an image title (a string). Unlike selectWindow(), this function works with macros running in batch mode.selectWindow("name")
Activates the image window with the title "name". Also activates non-image windows in v1.30n or later.setBackgroundColor(r, g, b)
Sets the background color, where r, g, and b are >= 0 and <= 255.setBatchMode(boolean)
If boolean is true, the interpreter enters batch mode and images are not displayed, allowing the macro to run up to 20 times faster. In batch mode, you must use selectImage() to select images and close() to close them. Four example macros are available: BatchModeTest, BatchMeasure, BatchSetScale and BatchRGBMeasureWithRois. Requires v1.33n or later.setColor(r, g, b)
Sets the drawing color, where r, g, and b are >= 0 and <= 255. This function is faster than setForegroundColor() and does not change the system wide foreground color or repaint the color picker tool icon.setColor(value)
Sets the drawing color. For 8 bit images, 0<=value<=255. For 16 bit images, 0<=value<=65535. For RGB images, use hex constants (e.g., 0xff0000 for red). This function does not change the foreground color used by run("Draw") and run("Fill").setFont(name, size[, style])
The first argument is the font name. It should be "SansSerif", "Serif" or "Monospaced". The second argument is the point size of the font. The optional third argument is a string containing "bold" or "italic", or both. For examples, run the TextDemo macro. Requires v1.33j or later.setForegroundColor(r, g, b)
Sets the foreground color, where r, g, and b are >= 0 and <= 255.setJustification("center")
Specifies the justification used by drawString() and Plot.addText(). The argument can be "left", "right" or "center". The default is "left". Requires v1.31l or later.setKeyDown(keys)
Simulates pressing the shift, alt or space keys, where keys is a string containing some combination of "shift", "alt" or "space". Any key not specified is set "up". Use setKeyDown("none") to set all keys in the "up" position. For an example, see the DoWandDemo macro. Requires ImageJ 1.33c.setLineWidth(width)
Specifies the line width (in pixels) used by drawLine() and lineTo().setLocation(x, y)
Moves the active image window to a new location.setLut(reds, greens, blues)
Creates a new lookup table and assigns it to the current image. Three input arrays are required, each containing 256 intensity values. See the LookupTables macros for examples.setMinAndMax(min, max)
Sets the minimum and maximum displayed pixel values (display range). See the DisplayRangeMacros for examples.setPasteMode("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".setPixel(x, y, value)
Stores value at location (x,y) of the current image. The screen is updated when the macro exits or call updateDisplay() to have it updated immediately.setResult("Column", row, value)
Adds an entry to the ImageJ results table or modifies an existing entry. The first argument specifies a column in the table. If the specified column does not exist, it is added. The second argument specifies the row, where 0<=row<=nResults. (nResults is a predefined variable.) A row is added to the table if row=nResults. The third argument is the value to be added or modified. Call setResult("Label", row, string) to set the row label (v1.33n or later). Call updateResults() to display the updated table in the "Results" window. For an examples, see the SineCosineTable and ConvexitySolidarity macros. Requires v1.31g.setThreshold(lower, upper)
Sets the lower and upper threshold levels.setTool(id)
Switches to the specified tool, where 0=rectangle, 1=oval, 2=polygon, 3=freehand, 4=straight line, 5=polyline, 6=freeline, 7=point, 8=wand, 9=text, 10=spare, 11=zoom, 12=hand, 13=dropper, 14=angle, 15...19=spare.setupUndo()
Call this function before drawing on an image to allow the user the option of later restoring the original image using Edit/Undo. For an example, see the DrawingTools tool set. Requires v1.32g.setZCoordinate(z)
Sets the Z coordinate used by getPixel(), setPixel() and changeValues(). The argument must be in the range 0 to n-1, where n is the number of images in the stack. For an examples, see the Z Profile Plotter Tool. Requires v1.31l.showMessage(["title",]"message")
Displays "message" in a dialog box. "Title" (optional) is the dialog box title.showMessageWithCancel(["title",]"message")
Displays "message" in a dialog box with "OK" and "Cancel" buttons. "Title" (optional) is the dialog box title. The macro exits if the user clicks "Cancel" button.showProgress(progress)
Updates the ImageJ progress bar, where 0.0<=progress<=1.0. The progress bar is not displayed if the time between the first and second calls to this function is less than 30 milliseconds. It is erased when the macro terminates or progress is >=1.0.showStatus("message")
Displays a message in the ImageJ status bar.sin(angle)
Returns the sine of an angle (in radians).snapshot()
Creates a backup copy of the current image that can be restored using reset().split(string, delimiters)
Breaks a string into an array of substrings. Delimiters is a string containing one or more delimiter characters. The default delimiter set " \t\n\r" (space, tab, newline, return) is used if delimiters is an empty string. Returns a one element array if no delimiter is found.sqrt(n)
Returns the square root of n.startsWith(string, prefix)
Returns true (1) if string starts with prefix. See also: endsWith, indexOf, substring. Requires v1.32f.substring(string, index1, index2)
Returns a new string that is a substring of string. The substring begins at index1 and extends to the character at index2 - 1. See also: indexOf, startsWith, endsWith.tan(angle)
Returns the tangent of an angle (in radians).toBinary(number)
Returns a binary string representation of number.toHex(number)
Returns a hexadecimal string representation of number.updateDisplay()
Redraws the active image.updateResults()
Call this function to update the "Results" window after the results table has been modified by calls to the setResult() function. Requires v1.31g.wait(n)
Delays (sleeps) for n milliseconds.write(string)
Outputs a string to the "Results" window. Numeric arguments are automatically converted to strings.