Skip to content

Instantly share code, notes, and snippets.

@bogovicj
Created February 23, 2018 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bogovicj/2a3edaea7ec62bd5e79e6f508ec5553e to your computer and use it in GitHub Desktop.
Save bogovicj/2a3edaea7ec62bd5e79e6f508ec5553e to your computer and use it in GitHub Desktop.
trakem2_exportAreaLists.bsh
import ij.IJ;
import ij.ImagePlus;
import java.util.ArrayList;
import ini.trakem2.Project;
import ini.trakem2.tree.ProjectThing;
import ini.trakem2.display.Display;
import ini.trakem2.display.AreaList;
destdir="/home/john/tmp/tem2/";
type = ImagePlus.GRAY8;
/*
* This function starts at the root Project thing
* and recursively finds AreaLists.
* When it does, it writes a tif file to the 'destdir',
* where the tif file name consists of the titles of all
* project things
*/
void writeArealists( ProjectThing root, String prefix )
{
// put a check here to be sure root is okay
if( root == null )
return;
// add this object's title to the file name
thisprefix = prefix + "_" + root.getTitle();
// get this project's object and see if it's an AreaList
obj = root.getObject();
if( obj instanceof AreaList )
{
// if so, write a tif
ip = ((AreaList)obj).getStack( type, 1.0 );
IJ.save( ip, destdir + thisprefix + ".tif" );
}
// recurse
children = root.getChildren();
if( children != null )
{
for( int i = 0; i < children.size(); i++ )
{
c = children.get( i );
writeArealists( c, thisprefix );
}
}
}
// get the root ProjectThing
project = Project.getProjects().get(0);
root = project.getRootProjectThing();
// call the function
writeArealists( root, "" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment