abs(n)
Returns the absolute value of n.acos(n)
Returns the arc cosine (in radians) of n. Requires 1.34h.asin(n)
Returns the arc sine (in radians) of n. Requires 1.34h.atan(n)
Calculates the inverse tangent (arc tangent) of n. Returns a value in the range -PI/2 through PI/2.atan2(y, x)
Calculates the arctangent of y/x and returns an angle in the range -PI to PI, using the signs of the arguments to determine the quadrant. Multiply the result by 180/PI to convert to degrees.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).calibrate(value)
Uses the calibration function of the active image to convert a raw pixel value to a density calibrated value. The argument must be an integer in the range 0-255 (for 8-bit images) or 0-65535 (for 16-bit images). Returns the same value if the active image does not have a calibration function. Requires 1.34h.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. This function has the advantage of not closing the "Log" or "Results" window when you meant to close the active image.cos(angle)
Returns the cosine of an angle (in radians).d2s(n, decimalPlaces)
Converts the number n into a string using the specified number of decimal places. Note that d2s stands for "double to string". This function will probably be replaced by one with a better name.Dialog.create("Title")
Creates a dialog box with the specified title. Call Dialog.addString(), Dialog.addNumber(), etc. to add components to the dialog. Call Dialog.show() to display the dialog and Dialog.getString(), Dialog.getNumber(), etc. to retrieve the values entered by the user. Refer to the DialogDemo macro for an example. Requires 1.34m.
Dialog.addMessage(string) - Adds a message to the dialog. The message can be broken into multiple lines by inserting new line characters ("\n") into the string.doCommand("Command")
Dialog.addString("Label", "Initial text") - Adds a text field to the dialog, using the specified label and intial text.
Dialog.addNumber("Label", default) - Adds a numeric field to the dialog, using the specified label and default value.
Dialog.addNumber("Label", default, decimalPlaces, columns, units) - Adds a numeric field, using the specified label and default value. DecimalPlaces specifies the number of digits to right of decimal point, columns specifies the the field width in characters and units is a string that is displayed to the right of the field. Requires 1.35b.
Dialog.addCheckbox("Label", default) - Adds a checkbox to the dialog, using the specified label and default state (true or false).
Dialog.addChoice("Label", items) - Adds a popup menu to the dialog, where items is a string array containing the menu items.
Dialog.addChoice("Label", items, default) - Adds a popup menu, where items is a string array containing the choices and default is the default choice.
Dialog.show() - Displays the dialog and waits until the user clicks "OK" or "Cancel". The macro terminates if the user clicks "Cancel".
Dialog.getString() - Returns a string containing the contents of the next text field.
Dialog.getNumber() - Returns the contents of the next numeric field.
Dialog.getCheckbox() - Returns the state (true or false) of the next checkbox.
Dialog.getChoice() - Returns the selected item (a string) from the next popup menu.
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. Note that some objects, especially one pixel wide lines, may not be reliably traced unless they have been thresholded (highlighted in red) using setThreshold.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.eval(macro)
Evaluates (runs) one or more lines of macro code. See also: EvalDemo macro and runMacro function. Requires v1.34g.exit() or exit("error message")
Terminates execution of the macro and, optionally, displays an error message.exp(n)
Returns the exponential number e (i.e., 2.718...) raised to the power of n.File functions
These functions allow you to get information about files, to delete files and directories, and to create directories. The FileDemo macro demonstrates how to use them. See also: getDirectory and getFileList. Requires 1.35g.
File.exists(path) - Returns true if the specified file exists.fill()
File.getName(path) - Returns the last name in path's name sequence.
File.getParent(path) - Returns the parent of the file specified by path.
File.getAbsolutePath(path) - Returns the full path of the file specified by path.
File.isDirectory(path) - Returns true if the specified file is a directory.
File.length(path) - Returns the length in bytes of the specified file.
File.makeDirectory(path) - Creates a directory.
File.dateLastModified(path) - Returns the date and time the specified file was last modified.
File.lastModified(path) - Returns the time the specified file was last modified as the number of milliseconds since January 1, 1970.
File.delete(path) - Deletes the specified file. If the file is a directory, it must be empty. The file must be in the ImageJ or temp directory.
File.separator - Returns the file name separator character ("/" or "\").
File.openAsString(path) - Opens a text file and returns the contents as a string. Displays a file open dialog box if path is an empty string. Use lines=split(str,"\n") to convert the string to an array of lines. Requires 1.35r.
File.open(path) - Creates a new text file and returns a file variable that refers to it. To write to the file, pass the file variable to the print() function. Displays a file save dialog box if path is an empty string. The file is closed when the macro exits. For an example, refer to the OpenFileDemo macro. Requires 1.35r.
File.close(f) - Closes the specified file, which must have been opened using File.open(). Requires 1.35r.
Fills the image or selection with the current drawing color.fillRect(x, y, width, height)
Fills the specified rectangle with the current drawing color. See also: setColor, autoUpdate. Requires 1.34g.floodFill(x, y)
Fills, with the foreground color, pixels that are connected to, and the same color as, the pixel at (x, y). This function is used to implement the flood fill (paint bucket) macro tool. Requires 1.34j.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 runMacro(macro, arg), eval(macro), IJ.runMacro(macro, arg) or IJ.runMacroFile(path, arg).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".getBoundingRect(x, y, width, height)
Replace by getSelectionBounds.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 examples, see the GetCursorLocDemo and the GetCursorLocDemoTool macros.getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec)
Returns the current date and time. For an example, refer to the GetDateAndTime macro. See also: getTime. Requires v1.34n or later.getDirectory(title)
Returns the path to a specified directory. If title is "startup", returns the path to the directory that ImageJ was launched from (usually the ImageJ directory). If it is "plugins" or "macros", returns the path to the plugins or macros folder. If it is "image", returns the path to the directory that the active image was loaded from. If it is "home", returns the path to users home directory. If it is "temp", returns the path to the /tmp directory. Otherwise, displays a dialog (with title as the title), 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 examples, see the GetDirectoryDemo and ListFilesRecursively macros.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.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.getImageInfo()
Returns a string containing the text that would be displayed by the Image/Show Info command. To retrieve the contents of a text window, use getInfo(). For an example, see the ListDicomTags macros.getInfo()
If the front window is a text window, returns the contents of that window. If the front window is an image, returns a string containing the text that would be displayed by Image/Show Info. Note that getImageInfo() is a more reliable way to retrieve information about an image. 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.getLocationAndSize(x, y, width, height)
Returns the location and size of the active image window. Use getWidth and getHeight to get the width and height of the active image. See also: setLocation, Requires v1.34k or later.getHeight()
Returns the height in pixels of the current image.getHistogram(values, counts, nBins[, histMin, histMax])
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 the bin starts for 16 and 32 bit images), 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, or an integer greater than zero for 16 and 32 bit images. With 16-bit images, the Values argument is ignored if nBins is 65536. With 16-bit and 32-bit images, and ImageJ 1.35a and later, the histogram range can be specified using optional histMin and histMax arguments. See also: getStatistics, HistogramLister, HistogramPlotter, StackHistogramLister and CustomHistogram.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.getMetadata()
Returns the metadata (a string) associated with the current image or stack slice. With stacks, the first line of the metadata is the slice label. With DICOM images and stacks, returns the metadata from the DICOM header. See also: setMetadata. Requires v1.34q.getMinAndMax(min, max)
Returns the minimum and maximum displayed pixel values (display range). See the DisplayRangeMacros for examples.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. See also: Dialog.create.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 shows how to do this.getPixelSize(unit, pixelWidth, pixelHeight)
Returns the unit of length (as a string) and the pixel dimensions. For an example, see the ShowImageInfo macro. See also: getVoxelSize.getProfile()
Runs Analyze/Plot Profile (without displaying the plot) and returns the intensity values as an array. For an example, see the GetProfileExample macro.getRawStatistics(nPixels, mean, min, max, std, histogram)
This function is similar to getStatistics except that the values returned are uncalibrated and the histogram of 16-bit images has a bin width of one and is returned as a max+1 element array. For examples, refer to the ShowStatistics macro set. See also: calibrate. Requires 1.34h.getResult("Column", row)
Returns a measurement from the ImageJ results table or NaN if the specified column is not found. 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.) With ImageJ 1.34g and later, you can omit the second argument and have the row default to nResults-1 (the last row in the results table). See also: nResults, setResult, isNaN, getResultLabel.getResultLabel(row)
Returns the label of the specified row in the results table or an empty string if the row does not have a label. Requires v1.35r or later.getSelectionBounds(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). See also: selectionType. Requires v1.34g or later.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. See also: selectionType, getSelectionBounds.getSliceNumber()
Returns the number of the currently displayed stack slice, an integer between 1 and nSlices. Returns 1 if the active image is not a stack. See also: setSlice. Requires 1.34g.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. See also: Dialog.create.getStatistics(area, mean, min, max, std, histogram)
Returns the area, average pixel value, minimum pixel value, maximum pixel value, standard deviation of the pixel values and histogram of the active image or selection. The histogram is returned as a 256 element array. For 8-bit and RGB images, the histogram bin width is one. For 16-bit and 32-bit images, the bin width is (max-min)/256. For examples, refer to the ShowStatistics macro set. Note that trailing arguments can be omitted. For example, you can use getStatistics(area), getStatistics(area, mean) or getStatistics(area, mean, min, max). See also: getRawStatistics Requires 1.34h.getThreshold(lower, upper)
Returns the lower and upper threshold levels. Both variables are set to -1 if the active image is not thresholded. See also: setThreshold, getThreshold, resetThreshold.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. See also: getDateAndTime.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. See also: getPixelSize, setVoxelSize.getVersion()
Returns the ImageJ version number as a string (e.g., "1.34s"). Requires v1.35m. See also: requires.getWidth()
Returns the width in pixels of the current image.getZoom()
Returns the magnification of the active image, a number in the range 0.03125 to 32.0 (3.1% to 3200%).imageCalculator(operator, img1, img2)
Runs the Process/Image Calculator tool, where operator ("add","subtract","multiply","divide", "and", "or", "xor", "min", "max", "average", "difference" or "copy") specifies the operation, and img1 and img2 specify the operands. img1 and img2 can be either an image title (a string) or an image ID (an integer). The operator string can include up to three modifiers: "create" (e.g., "add create") causes the result to be stored in a new window, "32-bit" causes the result to be 32-bit floating-point and "stack" causes the entire stack to be processed. See the ImageCalculatorDemo macros for examples. Requires v1.34r.indexOf(string, substring)
Returns the index within string of the first occurrence of substring. See also: lastIndexOf, startsWith, endsWith, substring, toLowerCase, replace.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.isKeyDown(key)
Returns true if the specified key is pressed, where key must be "shift", "alt" or "space". See also: setKeyDown.isNaN(n)
Returns true if the value of the number n is NaN (Not-a-Number). A common way to create a NaN is to divide zero by zero. This function is required because (n==NaN) is always false. Note that the numeric constant NaN is predefined in the macro language.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.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. Note that log10(n) = log(n)/log(10).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. With ImageJ 1.35b and letter, you can create segmented line selections by specifying more than two coordinate, for example makeLine(25,34,44,19,69,30,71,56).makeOval(x, y, width, height)
Creates an elliptical selection, where (x,y) define the upper left corner of the bounding rectangle of the ellipse.makePolygon(x1, y1, x2, y2, x3, y3, ...)
Creates a polygonal selection. At least three coordinate pairs must be specified, but not more than 200. As an example, makePolygon(20,48,59,13,101,40,75,77,38,70) creates a polygon selection with five sides.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.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. You can also create arrays by listing the elements, for example newArray(1,4,7) or newArray("a","b","c"). For more examples, see the Arrays macro.The ImageJ macro language does not directly support 2D arrays. As a work around, either create a blank image and use setPixel() and getPixel(), or create a 1D array using a=newArray(xmax*ymax) and do your own indexing (e.g., value=a[x+y*xmax]).
newImage(title, type, width, height, depth)
Opens a new image or stack using the name title. The string type should contain "8-bit", "16-bit", "32-bit" or "RGB". In addition, it can contain "white", "black" or "ramp" (the default is "white"). As an example, use "16-bit ramp" to create a 16-bit image containing a grayscale ramp. Width and height specify the width and height of the image in pixels. Depth specifies the number of stack slices.nImages
Returns number of open images. The parentheses "()" are optional.nResults
Returns the current measurement counter value. The parentheses "()" are optional.nSlices
Returns the number of slices in the current stack. Returns 1 if the current image is not a stack. The parentheses "()" are optional. See also: getSliceNumber,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.parseFloat(string)
Converts the string argument to a number and returns it. Returns NaN (Not a Number) if the string cannot be converted into a number. Use the isNaN() function to test for NaN. For examples, see ParseFloatIntExamples.parseFloat(string)
Converts the string argument to a number and returns it. Returns NaN (Not a Number) if the string cannot be converted into a number. Use the isNaN() function to test for NaN. For examples, see ParseFloatIntExamples.parseInt(string)
Converts string to an integer and returns it. Returns NaN if the string cannot be converted into a integer.parseInt(string, radix)
Converts string to an integer and returns it. The optional second argument (radix) specifies the base of the number contained in the string. The radix must be an integer between 2 and 36. For radixes above 10, the letters of the alphabet indicate numerals greater than 9. Set radix to 16 to parse hexadecimal numbers. Returns NaN if the string cannot be converted into a integer. For examples, see ParseFloatIntExamples.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.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.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.Plot.setJustification("center")
Specifies the justification used by Plot.addText(). The argument can be "left", "right" or "center". The default is "left".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. Starting with v1.34b, this function accepts multiple arguments. For example, you can use print(x,y,width, height) instead of print(x+" "+y+" "+width+" "+height). 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.rename(name)
Changes the title of the active image to the string name.replace(string, old, new)
Returns the new string that results from replacing all occurrences of old in string with new, where old and new are single character strings. With Java 1.4 and later, replaces each substring of string that matches the regular expression old with new. Requires 1.34h.requires("1.29p")
Display a message and aborts the macro if the ImageJ version is less than the one specified. See also: getVersion.reset()
Restores the backup image created by the snapshot function.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. See also: setThreshold, setAutoThreshold, getThreshold.restoreSettings()
Restores Edit/Options submenu settings saved by the saveSettings() function.roiManager(cmd)
Runs an ROI Manager command, where cmd must be "Add", "Add & Draw", "Deselect", "Measure", "Draw" or "Combine". The ROI Manager is opened if it is not already open. With v1.34k or later, use roiManager("reset") to delete all items on the list. For examples, refer to the RoiManagerMacros, RoiManagerAddParticles and ROI Manager Stack Demo macros.roiManager(cmd, path)
Runs an ROI Manager I/O command, where cmd is "Open" or "Save and path is a file path. With 1.35c or later, the "Save" option ignores selections and saves all the ROIs as a ZIP archive. The ROI Manager is opened if it is not already open.roiManager("count")
Returns the number of items in the ROI Manager list. Requires v1.34k.roiManager("select", index)
Selects an item in the ROI Manager list, where index must be greater than or equal zero and less than the value returned by roiManager("count"). Use roiManager("deselect") to deselect all items on the list. For an example, refer to the ROI Manager Stack Demo macro. Requires v1.34k.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.runMacro(name)
Runs the specified macro file, which is assumed to be in the Image macros folder. A full file path may also be used. The ".txt" extension is optional. Returns any string argument returned by the macro. May have an optional second string argument that is passed to macro. For an example, see the CalculateMean macro. See also: eval and getArgument. Requires v1.34g.save(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", ".lut", ".roi" or ".txt".saveAs(format, path)
Saves the active image, lookup table, selection, measurement results, selection XY coordinates or text window to the specified file path. The format argument must be "tiff", "jpeg", "gif", "zip", "raw", "avi", "bmp", "text image", "lut", "selection", "measurements", "xy Coordinates" or "text". With v1.34k or later, use saveAs(format) to have a "Save As" dialog displayed.saveSettings()
Saves most Edit/Options submenu settings so they can be restored later by calling restoreSettings().screenHeight
Returns the screen height in pixels. See also: getLocationAndSize, setLocation. Requires v1.34g.screenWidth
Returns the screen width in pixels. Requires v1.34g.selectionName
Returns the name of the current selection, or an empty string if the selection does not have a name. Aborts the macro if there is no selection. Requires 1.35i. See also: setSelectionName and selectionType.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 zero, activates the idth image listed in the Window menu. With ImageJ 1.33n and later, id can be an image title (a string).selectWindow("name")
Activates the image window with the title "name". Also activates non-image windows in v1.30n or later.setAutoThreshold()
Sets the threshold levels based on an analysis of the histogram of the current image or selection. Equivalent to clicking on "Auto" in the Image/Adjust/Threshold window. See also: setThreshold, getThreshold, resetThreshold.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. If boolean is false, exits batch mode and displays the active image in a window. Here are five example batch mode macros: BatchModeTest, BatchMeasure, BatchSetScale and ExpandOrShrinkSelection, ReplaceRedWithMagenta.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.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".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. See also: isKeyDown.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. See also: getLocationAndSize, screenWidth, screenHeight.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.setMetadata(string)
Assigns the metadata contained in the specified string to the the current image or stack slice. With stacks, the first 15 characters, or up to the first newline, are used as the slice label. The metadata is always assigned to the "Info" image property (displayed by Image/Show Info) if string starts with "Info:". Note that the metadata is saved as part of the TIFF header when the image is saved. See also: getMetadata. Requires v1.34q.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 examples, see the SineCosineTable and ConvexitySolidarity macros.setRGBWeights(redWeight, greenWeight, blueWeight)
Sets the weighting factors used by the Analyze/Measure, Image/Type/8-bit and Analyze/Histogram commands when they convert RGB pixels values to grayscale. The sum of the weights must be 1.0. Use (1/3,1/3,1/3) for equal weighting of red, green and blue. The weighting factors in effect when the macro started are restored when it terminates. For examples, see the MeasureRGB, ShowRGBChannels and RGB_Histogram macros. Requires v1.35b.setThreshold(lower, upper)
Sets the lower and upper threshold levels. Starting with ImageJ 1.34g, there is an optional third argument that can be "red", "black & white", "over/under" or "no color". See also: setAutoThreshold, getThreshold, resetThreshold.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. See also: toolID.setupUndo()
Call this function before drawing on an image to allow the user the option of later restoring the original image using Edit/Undo. Note that setupUndo() may not work as intended with macros that call the run() function. For an example, see the DrawingTools tool set.setSelectionName(name)
Sets the name of the current selection to the specified name. Aborts the macro if there is no selection. Requires 1.35i. See also: selectionName and selectionType.setSlice(n)
Displays the nth slice of the active stack. Does nothing if the active image is not a stack. For an example, see the MeasureStack macros. See also: getSliceNumber, nSlices.setVoxelSize(width, height, depth, unit)
Defines the voxel dimensions and unit of length ("pixel", "mm", etc.) for the current image or stack. The depth argument is ignored if the current image is not a stack. See also: getVoxelSize. Requires v1.34k.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.showMessage("message")
Displays "message" in a dialog box.showMessage("title", "message")
Displays "message" in a dialog box using "title" as the 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 later restored using the reset function. For examples, see the ImageRotator and BouncingBar macros.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 or split is called with only one argument (v1.34j or later). Returns a one element array if no delimiter is found.sqrt(n)
Returns the square root of n. Returns NaN if n is less than zero.startsWith(string, prefix)
Returns true (1) if string starts with prefix. See also: endsWith, indexOf, substring, toLowerCase.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, replace.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.toLowerCase(string)
Returns a new string that is a copy of string with all the characters converted to lower case. Requires v1.34b.toolID
Returns the ID of the currently selected tool. Requires 1.35i. See also: setTool.toString(number)
Returns a decimal string representation of number. See also: toBinary, toHex, parseFloat and parseInt. Requires v1.34g.toUpperCase(string)
Returns a new string that is a copy of string with all the characters converted to upper case. Requires v1.34b.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.wait(n)
Delays (sleeps) for n milliseconds.write(string)
Outputs a string to the "Results" window. Numeric arguments are automatically converted to strings.