Unpack To PNG

PlugIn for ImageJ


You almost certainly don't need this plugin. ImageJ will export image stacks as sequences of PNG files via File -> Save As -> Image Sequence, and this can be nicely scripted in a macro.

You might want to use this plugin instead because of one of these reasons:

If those sound like bizarre things to want to do, then the real motivation is creating pages such as this learning tool for fruit fly neuroanatomy.

Please let me know of any problems you have with this plugin or any suggestions you have. I hope it is of some use to you.


This plugin was written by Mark Longair apart from the AmiraMesh file loading that was written by Johannes Schindelin.


You should download version 1.0 of the plugin. To install the plugin, copy that jar file to your ImageJ plugins directory. When you restart ImageJ it should appear in a "stacks" (n.b. not "Stacks") submenu of your Plugins menu.

The plugin requires at least Java version 1.5; if you get an exception that says something like "Bad version number in .class file" but you are using Java of version 1.5 or later please let me know and I'll try to find the problem.


The intention is that you should use this plugin from a macro with an invocation like the following:

     java -Xmx512m -jar ij.jar -eval "run('Unpack To PNG','filename=[/home/mark/CantonM43c.labels],directory=[/var/tmp/example-unpacked-stack]);"

That will open the label file /home/mark/CantonM43c.labels and unpack to a huge number of files in the directory /var/tmp/example-unpacked-stack.

You may notice when you try to overlay these files in a web browser that the PNG files are not properly transparent. As far as I can tell it is not possible using the Java image API to generate 8 bit paletted PNG files with an alpha value for each palette entry, although that is allowed in the PNG specification and supported in most modern web browser. So you have to post-process them with a small libpng program that I wrote, based on the example programs from the book "PNG: The Definitive Guide" You should download a tar archive with the set-png-transparency source code and build it by running ./build. You can then use it on all the files in a directory with bash commands something these (use with care!):

for i in *.png
   ../set-png-transparency/set-png-transparency $i $t 64 0
   if [ $? -ne 0 ]
       echo Failed

... and if you're happy with the PNG files ending .transparent, moving them back to their original names with:

for t in *.transparent
    i=`basename $t .transparent`
    mv $t $i
    if [ $? -ne 0 ]
       echo Move failed


This plugin is licensed under the GPL (the GNU General Public License version 3). The source code for the plugin is contained within the jar file.