Macro functions in ObjectJ

20 june 2009

ojNImages()

Returns the number of linked images as listed in the "Images" panel.

ojNObjects()

Returns the total number of objects.

ojNItems("itemType")

returns the number of items of a certain item type in the currently selected object (use "*" to count all items).

ojNPoints()

returns the number of points in the currently selected item

ojDeleteItem("itemType", n)

in the currently selected object, those markers that belong to the n-th item of itemType are deleted. Use "*" to count across all types. (1-based)

ojXPos(n)

ojYPos(n)

ojZPos(n)

returns the coordinate of the n-th point (1-based) of the currently selected item in fractional pixels (x, y) or fractional slices (z).

ojXYZPos(n)

dto, but returns all three coordinates as float array.

ojSelectObject(n)

selects and highlights the n-th object (1-based), and also selects the first item. Use n=0 to select none

ojSelectedObject()

returns the index of selected object, or zero if no object is selected.

ojSelectItem("itemType", n)

selects the n-th item (1-based) in the currently selected object (use "*" to count across all item types.

ojExtendVisibilityDepth(low, high)

extends visibility range of an item. Example: if a item has been marked in slice 5, then if low = 2 and high = 1 will make the item visible in slice 3, 4, 5 and 6.

ojShowImage(n)

displays the n-th image as listed in the panel "Linked images" (1-based).

ojShowObject(n)

displays the n-th object(1-based) upon its linked image.

ojImageLink()

returns the link number of the active image, e.g returns 3 if the image name appears at the third position on the list of linked images. A non-linked image returns 0.

ojFirstObject(n)

returns number of first object in the n-th linked image, or 0 if image is unmarked.

ojLastObject(n)

returns number of last object in the n-th linked image, or -1 if image is unmarked.

ojNPoints()

returns the number of points of the currently selected item

ojItemToRoi()

creates a selection from the currently selected item.

ojActiveItemName()

returns the name of the ObjectJ Tools that is highlighted in the ObjectJ Tools.


Setting markers

ojSetMarker(x, y)

sets a marker as if the user was clicking with current object tool into the active image. x and y can have fractional values.

ojSwitchToItem("name")

used to select a different item type before setting markers. "name" must be one of the defined item names.

ojOpenObject(n)

opens the n-th object, so that more markers can be added. Only one object can receive markers at a time.

ojSetComposite(b)

b=false sets collect mode to "single", so that an object can only contain a single item. b=true sets collect mode to "composite", so that an object can contain a whole collection of different items, that reside under the same object number and whose results populate the same row. This command only affects future point collection - it doesn't change existing objects.

ojCloseItem()

if an item with variable number of points such as polygon or segmented line is open, it is closed, otherwise nothing happens. (not yet implemented)

ojCloseObject()

if an object is open, it is closed, otherwise nothing happens. If "Composite Objects" is true, the frist item in the sequence is activated, otherwise the same item is active before and after.

ojAdvance()

activates next item type in ObjectJ Tools window. However, if an item is open, and more clones are allowed to be added, this command only closes the current item. If no more items are allowed to be added, the object is closed.

ojMovePoint(n, x, y, z)

moves the n-th point of currently selected item to a new location specified by x, y, z. Use -1 for x, y or z if no movement is desired in that direction.


Object results table
ojResult("column", row)

Returns a value from the object result array. The column can be specified either by number or by the title string. Returns NaN if that place is empty. (1-based)

ojSetResult("column", row, value)

Writes a value into the object result array. Use value = NaN for an empty field. (1-based)

ojInitColumn(columnTitle)

if the object results table contains a column with this title, it is cleared (i.e. it is filled with NaNs). If the column was static, it is made dynamic. If no column has this title, a new dynamic column is created in the object results. No algorithms will be attached.

ojDeleteColumn(columnTitle)

Deletes the object results column with that title. Use "*" to delete all columns, or other wildcards to delete a set of columns.

ojColumnNumber(columnTitle)

returns the index of the column with that title, or 0 if not found.

ojGetColumnTitle(columnIndex)

returns the title of column with that index.

ojNColumns()

returns total number of ObjectJ result columns

ojSetColumnProperty(columnTitle, name, value)

changes appearance of the column with that column title, or a of a set of columns if wildcards are used. Name- value pairs can be: "sort": 0= don't sort, 1 = min at top, 2 = max at top "digits": 0 .. 9 "width": column width in pixels; 0 is automatic "color": color (eg 0xff0000 is red, 0x00ff00 is green, 0x0000ff is blue, 0 is black) "visible": 0= hidden, 1 = visible Example: ojColumnOptions("Area", "sort", 1); sorts the column "Area" so min is at top.

ojGetStatistics(columnTitle, operation)

returns a statistical value of a column. Operation can be: "count", "mean", "min", "max", "sum", "stdev", "cv%". The returned value is NaN if the calculation is impossible. Only qualified objects are used for calculation.

ojPutOperand(itemName, itemIndex, pointIndex)

adds an operand to the most recently created column. An operand addresses a certain point in an object. See example xxx.

ojPutOperation(operation)

adds an operation to the most recently created column. The operation such as "length", "distance", "angle", defines which algorithm will be applied to the defined operands to get the results.

ojQualified(n)

returns true if n-th object is qualified.

ojQualify(n, flag)

qualifies n-th object if flag is true, disqualifies it if flag is false. -

ojLastRow(columnTitle)

returns index of last row of a static column (1-based). Use wildtype to obtain largest index of a group of columns. Returns zero if no static column has this title. Project file

ojGetProjectName()

Returns name of the project without the .ojj extension.

ojShowResults()

Brings the ObjectJ results window to the front

ojHideResults()

Closes the ObjectJ results window

ojGetProjectPath()

Returns directory path of current project, such as "/Users/oetzi/MiniProject/" Non-ObjectJ macros

ojSwapSlices(n1, n2)

Swaps two slices; does nothing if n1 or n2 is out of range 1..nSlices.

ojDeleteAllObjects()

deletes all objects

ojDeleteObject(n)

deletes the n-th object (1-based)

ojDisposeAllImages()

closes all image windows without saving

ojGetOpenObject()

returns index of opject that is currently open. (An open object is indicated by an asterisk after the number label).

ojInitTextColumn(columnTitle)

creates a new linked result column that can hold text.

ojObjectID(n)

returns the unique ID number of the n-th object; it is a negative number.

ojOwnerIndex(n)

returns index of the image that holds the n-th object.

ojOwnerIndex(n)

returns name of the image that holds the n-th object.

ojPutAlgorithm("area")

attaches an algorithm to a linked result column. Argument can be something like: "area", "count", "exists", "file", "id", "image", "none", "slice", "path", "length", "distance", "xpos", "ypos", "zpos", "angle", "orientation", "abspartialpath", "relpartialpath".

ojPutOperand("itemtype", clone, point)

adds an operand to the most recently created result column.

ojRoiToItem()

converts a standard roi into an object.

ojSelectedItemName()

returns the name of selected item

ojSetComposite(b)

allows creation of composite objects if b=true. This does not affect ojects that already exist.

ojSetItemVisible("ItemName", b)

shows or hides specified items depending on boolen b

ojSetTool(n)

positive n: selects tool in ImageJ window, and deselects ObjectJ tool negative n: selects ObjectJ tool, and deselects tool in ImageJ window

ojSet3D(b)

if b=true, objects are allowed to extend over more than one slice.

ojShowTools()

brings the ObjectJ Tools window to the front

ojZoom(factor, centerX, centerY)

if linked window is in front, it is zoomed by 'factor', and pixel location (centerX, centerY) is put to the center if possible.


Vertex calculator
The vertex calculator is a utility for performing geometric calculations. First, input parameters are pushed onto the "vertex stack", where each entry contains a 2d location (x,y); then a certain calculation can be performed. For example, you can push the three points of a triangle onto the stack and get result "area" of that triangle.

ojvInitStack("2d")

resets the vertex stack pointer to zero and prepares it for 2D calculations.

ojvPushVertex("x=33 y=44")

pushes a point position (vertex) onto the vertex stack

ojvPushItem()

pushes all points of selected item onto the vertex stack

ojvCalculate("operation")

returns a floating point result from the vertex stack. Possible operations: see table

Operation Comment

Line (2 entries)
orientation2 o'clock = 30 deg; 4 o'clock = -30 deg

Triangle (3 entries: A, B, C)
innercircle centerx
innercircle centery
innercircle radius
outercircle centerx
outercircle centery
outercircle radius
angleAngle at B (0..180 deg)
deviationDeviation at B when travelling A-B-C (range -180..0..180 deg, left is negative)
heightTriangle height at B onto A-C

Partial path (>=3 entries):
Finds the shortest line (spark line) from a point to a segmented line (=path). Stack must contain first the path, then the point. The spark line meets the path at the "impact point".
partialpathTravel distance along path until impact point
partialpath offsetlength of spark line
partialpath impactx
partialpath impacty
partialpath leftedgeindex of neighbor vertex towards start of path (zero-based)
partialpath rightedgeindex of neighbor vertex towards end of path (zero-based)

Segmented line and polygon(>=3 entries):
areapolygon area (if segments cross, sub-areas are subtracted)
perimeterperimeter of polygon (includes closing segment)
totalpathsum of all line segments

Two lines A-B and C-D (4 entries):
crosspointx
crosspointy