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:

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

I tried image.flatten() and got:

javax.script.ScriptException: Java class "[Lij.ImagePlus;" has no public instance field or method named "flatten".

I also tried


and got

javax.script.ScriptException: Can't find method ij.plugin.RGBStackMerge.mergeChannels($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, so I should have linked my answer there:

1 Like