Skip to content, Skip to search

Changes

TrakEM2 Scripting

1,471 bytes added, 13:04, 5 April 2011
Resetting the affine transform of all images in a Layer
The bucket is the region of the 2D world where the Patch lives. Picture the world as a checkerboard, where a given image, wrapped in a Patch object, belongs to each of the square that it intersects. Failing to update the bucket will result in improper canvas repaints--the Patch cannot be found.
 
 
=== Adding areas to an AreaList by scanning pixel values in the slices of a stack ===
 
The script below is the same as the command "Import - Import labels as arealists".
 
<source lang="python">
from ini.trakem2 import Project
from ini.trakem2.utils import AreaUtils
from ini.trakem2.display import AreaList
from java.awt import Color
 
# Obtain an image stack
#imp = IJ.getImage()
imp = WindowManager.getImage("0_5_filtered.tif")
 
# Obtain the opened TrakEM2 project
p = Project.getProjects()[0]
 
# Obtain the LayerSet
layerset = p.getRootLayerSet()
 
# Create a new AreaList, named "synapses"
ali = AreaList(p, "synapses", 0, 0)
 
# Add the AreaList to the datastructures:
layerset.add(ali)
p.getProjectTree().insertSegmentations([ali])
 
# Obtain the image stack
stack = imp.getImageStack()
 
# Iterate every slice of the stack
for i in range(1, imp.getNSlices() +1):
ip = stack.getProcessor(i) # 1-based
# Extract all areas (except background) into a map of value vs. java.awt.geom.Area
m = AreaUtils.extractAreas(ip)
# Report progress
print i, ":", len(m)
# Get the Layer instance at the corresponding index
layer = layerset.getLayers().get(i-1) # 0-based
# Add the first Area instance to the AreaList at the proper Layer
ali.addArea(layer.getId(), m.values().iterator().next())
 
# Change the color of the AreaList
ali.setColor(Color.magenta)
 
# Ensure bounds are as constrained as possible
ali.calculateBoundingBox(None)
 
Display.repaint()
 
</source>
= Adding images =
Emailconfirmed, uploaders
653
edits