Created
February 23, 2018 17:33
-
-
Save bogovicj/2a3edaea7ec62bd5e79e6f508ec5553e to your computer and use it in GitHub Desktop.
trakem2_exportAreaLists.bsh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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