Skip to content, Skip to search


TrakEM2 Scripting

616 bytes removed, 15:43, 16 July 2012
Fix links
Documentation you may want to look at:
[http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/Project.html#newFSProject(java.lang.String,%20ini.trakem2.tree.TemplateThing,%20java.lang.String) Project.newFSProject], [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Patch.html#createPatch(ini.trakem2.Project,%20java.lang.String) Patch.createPatch], [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Layer.html#add(ini.trakem2.display.Displayable) Layer.add], [http://pacificfiji.mpi-cbg.desc/javadoc/mpicbg/trakem2/align/Align.html Align], [http://pacific.mpi-cbgfiji.desc/javadoc/mpicbg/trakem2/align/AlignTask.html AlignTask],
# ... above, adjust other parameters as necessary
# See:
# features: http://pacificfiji.mpi-cbg.desc/javadoc/mpicbg/trakem2/align/Align.Param.html# transformation models: http://pacificfiji.mpi-cbg.desc/javadoc/mpicbg/trakem2/align/Align.ParamOptimize.html# sift: http://pacific.mpi-cbgfiji.desc/javadoc/mpicbg/imagefeatures/FloatArray2DSIFT.Param.html
AlignTask.montageLayers(param, layerset.getLayers(), False, False, False, False)
=== Calibrating and setting the Z dimension ===
Each [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Layer.html Layer] stores a Z coordinate and a thickness value with <i>double</i> precision. The Z coordinate is in pixels.
How to compute the Z coordinate of a [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Layer.html Layer]: suppose that the calibration specifies 4x4x50 nm. This means 4 nm/px in the X axis, 4 nm/px in the Y axis, and 50 nm/px in the Z axis. It is assumed that you set this values by right-clicking on the canvas window and choosing "Display - Calibration...", which opens the familiar ImageJ dialog for image calibration.
Then you have to compute the thickness of a section relative to X axis coordinates. To do so:
= Interacting with Treeline, AreaTree and Connector =
All three types: "treeline", "areatree", and "connector" are expressed by homonimous classes that inherit from the abstract class [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Tree.html ini.trakem2.display.Tree].
A [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Tree.html Tree] is a [http://pacific.mpi-cbgfiji.desc/javadoc/ini/trakem2/display/Displayable.html Displayable] and hence presents properties such as title, alpha, color, locked, visible ... which are accessible with their homonimous set and get methods (e.g. <I>setAlpha(0.8f);</i>, <i>getAlpha();</i> etc.)
The [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Tree.html Tree] consists of a root [http://pacific.mpi-cbgfiji.desc/javadoc/ini/trakem2/display/Node.html Node] and public methods to access it and modify it.
The root [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Node.html Node] gives access to the rest of the nodes of the [http://pacific.mpi-cbgfiji.desc/javadoc/ini/trakem2/display/Tree.html Tree]. From the canvas, a user would push 'r' on a selected Treeline, AreaTree or Connector to bring the field of view to where the root node is. From code, we would call:
<source lang="python">
Now that we have a reference to the root [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Node.html Node], we'll ask it to give us the entire collection of subtree nodes: all nodes in the [http://pacific.mpi-cbgfiji.desc/javadoc/ini/trakem2/display/Tree.html Tree]:
<source lang="python">
The [http://pacificfiji.mpi-cbg.desc/javadoc/ini.trakem2/display/Node.NodeCollection.html NodeCollection] is lazy and doesn't do caching. If you are planning on calling size() on it, and then iterating its nodes, you would end up iterating the whole sequence twice. So let's start by duplicating it:
<source lang="python">
Each [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Node.html Node] has:
<li>X, Y coordinates, relative to the local coordinate system of the Tree that contains the [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Node.html Node].</li> <li>A reference to a layer (get it with nd.getLayer()). The [http://pacific.mpi-cbgfiji.desc/javadoc/ini/trakem2/display/Layer.html Layer] has a getZ() method to get the Z coordinate (in pixels).</li>
<li>A data field, which can be a radius or a java.awt.geom.Area (see below).</li>
Each [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Node.html Node] contains a [http://pacific.mpi-cbgfiji.desc/javadoc/ini/trakem2/display/Node.html#getData() getData()] public method to acquire whatever it is that it has:
<li>Treeline and Connector: its nodes [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Node.html#getData() getData()] return a radius. The default value is zero.</li> <li>AreaTree: its nodes [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Node.html#getData() getData()] return a [http://pacific.mpi-cbgfiji.desc/javadoc/java/awt/geom/Area.html java.awt.geom.Area] instance, or null if none yet assigned to it.</li>
The method we use is [ Ulrik Brande]'s fast algorithm for computing betweenness centrality (see the [ paper]).
The method [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Tree.html#computeCentrality() computeCentrality()] of class [http://pacific.mpi-cbgfiji.desc/javadoc/ini/trakem2/display/Tree.html Tree] returns as a [http://pacific.mpi-cbgfiji.desc/javadoc/java/util/Map.html Map] of [http://pacific.mpi-cbgfiji.desc/javadoc/ini/trakem2/display/Node.html Node] instance vs. its centrality value:
<source lang="python">
== Compute the degree of every node ==
The degree of a node is the number of parent nodes that separate it from the root node. It's a built-in function in [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Tree.html Tree] (and also in [http://pacific.mpi-cbgfiji.desc/javadoc/ini/trakem2/display/Tree.html Node]):
In the following example, we colorize the tree based on the degree of the node: the closer to the root, the hotest:
== Find branch nodes or end nodes ==
The [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Tree.html Tree] class offers methods to obtain the list of all branch points, end points, or both:
<source lang="python">
Similarly, we could compute the incomming connections. There is a convenience method [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Tree.html#findConnectors() findConnectors()] in class [http://pacific.mpi-cbgfiji.desc/javadoc/ini/trakem2/display/Tree.html Tree] to return two lists: that of the outgoing and that of the incomming Connector instances. From these, one can easily get the connectivity graph, which you may also get by right-clicking on a Display and going for "Export - Connectivity graph...".
== How to find out the network of all arbors, related via Connector instances ==
The easiest way is to iterate all connectors and find out which objects they are relating. A [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Connector.html Connector] object has an origin (the root node) and any number of targets (all children nodes of the root node). Each node has a radius; any other object in the TrakEM2 project that intersects with the world coordinates of that radius will be considered associated as an origin or a target.
<source lang="python">
= Generate 3D meshes =
In TrakEM2, 3D meshes are generated as a list of [ Point3f] for each object. Then the list is wrapped into any of the subclasses of [http://pacificfiji.mpi-cbg.desc/javadoc/customnode/CustomMesh.html CustomMesh] of the 3D Viewer library, such as a [http://pacificfiji.mpi-cbg.desc/javadoc/customnode/CustomTriangleMesh.html CustomTriangleMesh] or a [http://pacificfiji.mpi-cbg.desc/javadoc/customnode/CustomLineMesh.html CustomLineMesh]. Then these mesh objects are encapsulated into a [http://pacificfiji.mpi-cbg.desc/javadoc/ij3d/Content.html Content] object and added to an instance of the [http://pacific.mpi-cbgfiji.desc/javadoc/ij3d/Image3DUniverse.html Image3DUniverse], which is the main window of the 3D Viewer.
Of course, via scripting many of these steps may be skipped. Below are several examples on how to generate meshes programmatically and save them in [ Wavefront] format.
The [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/AreaTree.html AreaTree]'s generateMesh returns a [http://pacific.mpi-cbgfiji.desc/javadoc/ini/trakem2/display/Tree.MeshData.html MeshData] object with the list of vertices and the list of colors of each vertex. The <i>generateTriangles</i> method of an [http://pacific.mpi-cbgfiji.desc/javadoc/ini/trakem2/display/AreaTree.html AreaTree] returns a list of [ Point3f] that are ready for creating a [http://pacific.mpi-cbgfiji.desc/javadoc/customnode/CustomLineMesh.html CustomLineMesh] (in PAIRWISE mode) to represent the skeleton.
= Save the project while running a task =
From the right-click menu, one may choose "Export - Make flat image", which opens a dialog that lets one choose between 8-bit and RGB. These snapshots are created from the mipmaps, which are all 8-bit or RGB images.
On occasions, one wants to create a flattened montage of images in their original bit depth, such as 16-bit or 32-bit. For this purpose, the static function [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Patch.html#makeFlatImage(int,%20ini.trakem2.display.Layer,%20java.awt.Rectangle,%20double,%20java.util.Collection,%20java.awt.Color,%20boolean) Patch.makeFlatImage] exists.
Here is an example that, for a given Layer and set of selected Patch instances (image tiles) in it, it makes a 16-bit flat montage image and returns it as an ImageJ's ImageProcessor, at 50% the original scale.
For other output types, use ImagePlus.GRAY8, .GRAY16, GRAY32 or .COLOR_RGB, as listed in the documentation for the [http://pacificfiji.mpi-cbg.desc/javadoc/ij/ImagePlus.html ImagePlus] class.
= Enrich the GUI of TrakEM =
All the following are included in Fiji's plugins/Examples/TrakEM2_Example_Scripts/ folder:
*[http://pacific.mpi-cbgfiji.desc/cgi-bin/gitweb.cgi?p=fiji.git;a=blob;f=plugins/Examples/TrakEM2_Example_Scripts/;hb=HEAD Extract stack under AreaList] in TrakEM2.*[http://pacificfiji.mpi-cbg.desc/cgi-bin/gitweb.cgi?p=fiji.git;a=blob;f=plugins/Examples/TrakEM2_Example_Scripts/;hb=HEAD Set all transforms to identity] for TrakEM2 objects.*[http://pacificfiji.mpi-cbg.desc/cgi-bin/gitweb.cgi?p=fiji.git;a=blob;f=plugins/Examples/TrakEM2_Example_Scripts/;hb=HEAD Select All] objects in TrakEM2.*[http://pacificfiji.mpi-cbg.desc/cgi-bin/gitweb.cgi?p=fiji.git;a=blob;f=plugins/Examples/TrakEM2_Example_Scripts/;hb=HEAD Measure AreaList] in TrakEM2.* A [ collection of scripts for TrakEM2], hosted by github. Mostly related to inspecting and analyzing [http://pacificfiji.mpi-cbg.desc/javadoc/ini/trakem2/display/Treeline.html Treeline], [http://pacific.mpi-cbgfiji.desc/javadoc/ini/trakem2/display/AreaTree.html AreaTree] and [http://pacific.mpi-cbgfiji.desc/javadoc/ini/trakem2/display/Connector.html Connector] instances, when used for neural circuit reconstruction.
Bureaucrat, incoming, administrator, uploaders