Skip to content, Skip to search


TrakEM2 Scripting

1,763 bytes added, 16:12, 3 February 2011
making flat image
print "done!"
= Create a snapshot in 8-bit, 16-bit, 32-bit or RGB =
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 [, ini.trakem2.display.Layer, java.awt.Rectangle, double, java.util.Collection, java.awt.Color, boolean) 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.
<source lang="python">
from ini.trakem2.display import Display, Patch
from java.awt import Color
front = Display.getFront() # the active TrakEM2 display window
layer = front.getLayer()
tiles = front.getSelection().get(Patch) # selected Patch instances only
backgroundColor =
scale = 0.5
roi = tiles[0].getBoundingBox()
for tile in tiles[1:]:
print "Creating flat image from", len(tiles), "image tiles"
ip = Patch.makeFlatImage(
True) # use the min and max of each tile
imp = ImagePlus("Flat montage", ip)
For other output types, use ImagePlus.GRAY8, .GRAY16, GRAY32 or .COLOR_RGB, as listed in the documentation for the [ ImagePlus] class.
= Enrich the GUI of TrakEM =
Emailconfirmed, uploaders