Javascript macro merge RGB channels

I’m reading in a cropped area from a three channel .svs image that I safe as a .tiff. Currently, the files are saving as a three channel image. I want to merge the channels.

I found two potential ways to do this:

http://javadoc.imagej.net/ImageJ1/?ij/plugin/RGBStackMerge.html

http://javadoc.imagej.net/ImageJ1/ij/ImagePlus.html#flatten()

	var path = currentFolder + "images" + File.separator + imageName; 
	var options = new ImporterOptions(); 
	options.setId(path); 
	options.setAutoscale(true); 
	options.setCrop(true); 
	options.setCropRegion(0, new Region(X, Y, deltaX, deltaY)); 
	options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE); 
	var imps = new ImagePlus();
	imps = BF.openImagePlus(options); 

I tried image.flatten() and got:

javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: Java class "[Lij.ImagePlus;" has no public instance field or method named "flatten".

I also tried

importClass(Packages.ij.plugin.RGBStackMerge);

and got

javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: Can't find method ij.plugin.RGBStackMerge.mergeChannels(loci.plugins.in.Colorizer$1,boolean).

So how can I access either the ImagePlus.flatten() or RGBStackMerge.mergeChannels?

The issue here is the BF.openImagePlus does not return an ImagePlus, but an array (i.e., a list) of ImagePlus.

So you should write:

var imps = BF.openImagePlus(options);
var firstFlatImage = imps[0].flatten();

I noticed only now that this is a cross-post from stackoverflow.com, so I should have linked my answer there:
http://stackoverflow.com/q/34960776/1919049

1 Like