package vis;

import ij.IJ;
import ij.ImagePlus;
import ij.plugin.RGBStackMerge;

public class Overlay
{

	static final String PROP_FORMAT ="channels=1 slices=%d frames=1 unit=pixel pixel_width=1.0000 pixel_height=1.0000 voxel_depth=1.0000";
	static final String MERGE_FORMAT ="c2=%s c6=%s create keep ignore";
	public static void main( String[] args )
	{
		String outpath = args[ 0 ];

		ImagePlus a = IJ.openImage( args[ 1 ]);
		IJ.run( a, "Properties...", String.format( PROP_FORMAT, a.getStackSize() ));
		a.setSlice( a.getStackSize() / 2 );
		IJ.run( a, "Enhance Contrast", "saturated=0.35");

		ImagePlus b = IJ.openImage( args[ 2 ]);
		IJ.run( b, "Properties...", String.format( PROP_FORMAT, b.getStackSize() ));
		b.setSlice( a.getStackSize() / 2 );
		IJ.run( b, "Enhance Contrast", "saturated=0.35");
		
		// this line makes 'b' green and 'a' magenta
		ImagePlus mergedIp = new ImagePlus( "result", RGBStackMerge.mergeStacks( a.getImageStack(), b.getImageStack(), a.getImageStack(), false ));
		System.out.println( "mergedIp: " + mergedIp );
	
		for( int i = 3; i < args.length; i++ )
		{
			int z = Integer.parseInt( args[ i ]);
			System.out.println( "z : " + z );

			mergedIp.setZ( z );
			ImagePlus ipout = new ImagePlus( "z:"+z, mergedIp.getProcessor() );

			IJ.save( ipout, outpath + z + ".png" );
		}

	}
	
}

@@ -7,16 +7,66 @@
 e vis;%0A%0A
+import java.io.File;%0Aimport java.io.IOException;%0A%0A
 import i
@@ -123,16 +123,76 @@
 ckMerge;
+%0Aimport io.nii.NiftiIo;%0Aimport loci.formats.FormatException;
 %0A%0Apublic
@@ -455,16 +455,52 @@
 %5D args )
+ throws FormatException, IOException
 %0A%09%7B%0A%09%09St
@@ -541,16 +541,120 @@
 Plus a =
+ null;%0A%09%09if( args%5B 1 %5D.endsWith( %22nii%22 ))%0A%09%09%09a = NiftiIo.readNifti( new File( args%5B1%5D ) );%0A%09%09else%0A%09%09%09a =
  IJ.open
@@ -668,24 +668,25 @@
 args%5B 1 %5D);%0A
+%0A
 %09%09IJ.run( a,
@@ -858,16 +858,122 @@
 Plus b =
+ null;%0A%09%09if( args%5B 2 %5D.endsWith( %22nii%22 ))%0A%09%09%09b = NiftiIo.readNifti( new File( args%5B 2 %5D ) );%0A%09%09else%0A%09%09%09b =
  IJ.open
@@ -991,16 +991,17 @@
 %5B 2 %5D);%0A
+%0A
 %09%09IJ.run

make overlay work with nii's