Usage of macros  |  ObjectJ functions | 

Macro functions in ObjectJ

15-jul-2021

ojActiveItemName()

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

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.

ojCloseItem()

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

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.

ojColumnNumber(columnTitle)

returns the index of the column with that title (1-based), or 0 if not found.

ojDeleteAllObjects()

deletes all objects

ojDeleteColumn(title)

Deletes the ObjectJ results column with that title, or several space-separated titles. Use "*" to delete all columns, or other wildcards to delete a set of columns.

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)

ojDeleteItems("itemA itemB")

in the currently selected object, all items with matching names are deleted. Accepts wildcard characters '*' and '?'

ojDeleteObject(n)

deletes the n-th object (1-based)

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.

ojFlatten()

creates an RGB image of same size as linked front image, with markers permanently burnt-in.

ojFirstObject(n)

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

ojGetColumn(title, includeAll)

returns numerical array of a column. Set includeAll=false to set the value of unqualified objects to NaN

ojGetColumnTitle(n)

returns the title of the n-th column (1-based).

ojGetImageValue(n, key)

returns numerical info of the n-th linked image (1-based), where key can be:
"width", "height", "channels", "slices", "frames", "stacksize", "ID", "frameinterval"
stacksize is product of channels, slices and frames. ID is negative if image is open, otherwise zero.

ojGetImageName(n)

returns the name of the n-th linked image (1-based)

ojGetItemName()

returns the name of item that has been selected via ojSelectItem

ojGetItemInfo()

returns info string of selected item

ojGetItemLength(itemName)

returns the length of selected item in pixels

ojGetItemNames()

returns the used item names in the order they are listed in the ObjectJ Tools window, separated by spaces

ojGetItemColors()

returns the used item colors in the order they are listed in the ObjectJ Tools window, separated by spaces

ojGetItemTypes()

returns the used item types (Point, Line etc) in the order they are listed in the ObjectJ Tools window, separated by spaces

ojGetObjectInfo()

returns info string of selected object

ojGetOpenObject()

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

ojGetProjectName()

Returns name of the project without the .ojj extension.

ojGetProjectPath()

Returns directory path of current project, such as "/Users/oetzi/MiniProject/"

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.

ojGetTarget()

If in target mode, target is returned as single string (image index and stack index, both 1-based). Otherwise, an empty string is returned.

ojGetVirtualFlag()

returns status of the virtual flag

ojGetVoxelSize(n, "x")

returns x-voxelsize of n-th linked image (1-based; ditto for "y" and "z")

ojHideResults()

Closes the ObjectJ results window

ojIdToIndex(id)

returns (1-based) index of the objact with that (negative) id, or zero if that object does not exist.

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.

ojIndexToId(index)

returns the unique (negative) id of the n-th object (n is 1-based). This macro was formerly called ojObjectID(n).

ojIndexToRank(n)

when ObjectJ linked results are sorted, the ranking of the n-th object is returned. Returns zero if out of range. (1-based)

ojIndexToRow(n)

returns rank of n-th object, useful in sort mode

ojInitColumn(columnTitle)

if the object results table contains a column with this title, it is cleared (i.e. it is filled with NaNs). If no column has this title, a new dynamic column is created in the object results. columTitle can contain several titles separated by spaces. ObjectJ Results is closed if it was open No algorithms will be attached (yet).

ojInitTextColumn(columnTitle)

creates column that can contain strings, or clears it if it already exists

ojItemToRoi()

creates a selection from the currently selected item.

ojLastObject(n)

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

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

ojLineToPolygon(linewidth, withRounding)

converts a segmented line roi into a polygon roi with defined line width. For now, set withRounding to false

ojLinkImage()

if active image is unlinked and saved in the project folder, it will be linked.

ojMatches(string, pattern)

returns true if string matches wildcard pattern (not case sensitive). Wildcards are * (for any substring including one with zero length) and ? (for any single character) Note: this is different from "matches()", which uses regular expressions.

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.

ojNColumns()

returns total number of ObjectJ result columns

ojNewestObject()

returns index (1-based) of object that was most recently open, or zero if not found

ojNImages()

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

ojNItems("itemType")

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

ojNObjects()

Returns the total number of objects.

ojNPoints()

returns the number of points of the currently selected item

ojOpenObject(n)

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

ojOrderObjectsInZ(n)

renumbers objects so number labels will ascend with stack index in n-th image. Use n=0 to include all linked images.

ojOwnerIndex(n)

returns index of the image that holds the n-th object; returns zero if n is out of range.

ojOwnerName(n)

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

ojPutAlgorithm("area")

attaches an algorithm to the most recently created 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.

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. -

ojRankToIndex(n)

when ObjectJ linked results are sorted, the index (1-based) of object with ranking n (1-based) is returned (smallest value is defined to have rank=1). Returns zero if out of range.

ojRecalculate()

Recalculates all dynamic results

ojRenameImage("oldName", "newName")

Renames a linked image in the project and renames the corresponding file on disk. The image needs not to be open. Make sure to save your .ojj project file after renaming.

ojRepositionItem(fromIndex, toIndex)()

Changes item order in selected object (1-based indexes); coordinates are not changed.

ojRequires("1.03")

Aborts macro if ObjectJ version is too old

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)

ojResultString("column", row)

Same as ojResult, but returns a string

ojRoiToItem()

converts a standard roi into an object.

ojRowToIndex(row)

returns index of object that appears in n-th row, useful in sort mode

ojSaveProject()

saves current project

ojFindClosestPoint(x, y, tolerance, itemName)

Searches closest object point in current image and slice, and selects corresponding object and item and returns the point number. Selects nothing and returns 0 if distance is larger than tolerance.

ojSelectedItemName()

returns the name of selected item

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.

ojSelectObject(n)

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

ojSet3D(b)

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

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
"label": show result as text overlay, 0= hidden, 1 = visible

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.

ojSetItemInfo(s)

sets info string of selected item

ojSetItemVisible("ItemName", b)

shows or hides specified items depending on boolen b

ojSetObjectInfo(s)

sets info string of selected object

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.

ojSetResult("column", row, value)

Writes a value into the object result array (row is 1-based). For numerical columns, use value=NaN to create an empty field. For text columns, use value="" to create an empty field.

ojSetTarget(argument)

Accellerates marking by avoiding screen updates (similar to batchmode). Target image needs not to be in front or open.
- ojSetTarget("frontimage") sets current image in target mode.
- ojSetTarget("exit") leaves target mode and updates screen and results.
- ojSetTarget("image=2") markers will be set into linked image #2
- ojSetTarget("channel=5") markers will be set into channel #5
- ojSetTarget("slice=5") markers will be set into slice #5 (used for hyperstack)
- ojSetTarget("frame=7") markers will be set into frame #7
- ojSetTarget("stackindex=9") markers will be set into stackindex #9
--- All parameters are one-based; stackindex regards a hyperstack as linear array of images.

ojSetTool(n)

positive n: selects tool in ImageJ window, and deselects ObjectJ tool, (also accepts name like "Rectangle")
negative n: deselects tool in ImageJ window and selects a tool in ObjectJ Tools (also accepts name like "Pistol", "Marker", "SelectObject", "MoveObject", "ObjectToRoi").

ojShowImage(n)

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

ojSetVirtualFlag(b)

if b=true, linked images will be opened virtually

ojSetUnchanged

marks project as unchanged

ojShowObject(n)

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

ojShowResults()

Brings the ObjectJ results window to the front

ojShowTools()

brings the ObjectJ Tools window to the front

ojSwitchToItem("name")

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

ojUpdateMarkers(b)

if b is set false, markers are not updated on the screen after ojSetMarker etc. until ojUpdateMarkers(true) is called

ojXPos(n), ojYPos(n), ojZPos(n)

returns the x- or y-coordinate of the n-th point (1-based) of the currently selected item in fractional pixels (x, y). The z position is same as the corresponding sliceNumber, but can also be fractional. returned as fractional slices, starting at 1 and

ojXYZPos(n)

ditto, but returns all three coordinates as float array.

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. These macro commands start with "ojv..."


ojvInitStack("2d")

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

ojvPushItem()

pushes all points of selected item onto the vertex stack

ojvPushPoint(n)

pushes n-th point of selected item onto the vertex stack (1-based)

ojvPushVertex("x=33 y=44")

pushes a point position (vertex) onto the vertex stack

ojvUndoPush()

removes the latest pushed object from the vertex stack

ojvGetStackSize()

returns the number of point objects on 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 signedoffsetoff-road left turn gives negative distance
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
partialpositionx 50%x position after traveling 50% of total path
partialpositiony 0.3y position after traveling 30% of total path
offpointx pathfraction=0.33 offset=12 travel 33% of total path then go 12 pixels offroad to the right, return x position (version 1.05g)
offpointy pathfraction=0.33 offset=-12 travel 33% of total path then go 12 pixels offroad to the left, return y position (version 1.05g)

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