Deinterleave not working in macro with setBatchMode(true)

imagej
batch-processing

#1

Hi everyone,

I wanted to speed up image processing using a macro with batch mode. One of the intial steps is to split a two channel-image using run(“Deinterleave”, “how=2”). This command does not work. However, a command like run(“Make Substack…”, " slices=1-20-2") nicely works.
Any suggestions?

Regards
DrChriSch


#2

@drchrisch

For me … the Deinterleave call works:

run("Deinterleave", "how=2");

What version of ImageJ/Fiji and Java are you running??

If you just need to separate channels, you could also try run("Split Channels");.

eta


#3

Hi eta,

Thanks for your response. There are several entries around batch mode and hidden images, but so far nobody reported problems using “Deinterleave”. However, trying the macro code below it throws an Exception. (Btw, “selectWindow”/“selectImage” does not make change). I feel a bit lost…

drchrisch

/*
   IJ1 Macro
 */
 
run("Close All");

setBatchMode(true);
//setBatchMode("show");

run("MRI Stack (528K)");
title = getTitle;

selectWindow(title);
run("Subtract Background...", "rolling=50 sliding");

selectWindow(title);
run("Stack Splitter", "number=3");

selectWindow(title);
run("Make Substack...", "  slices=1-27-6");
selectWindow(title);
run("Make Substack...", "  slices=2-27-6");
//counterFcn();

selectImage(title);
//selectWindow(title);
run("Deinterleave", "how=3");
counterFcn();

run("Close All");
setBatchMode(false);


// function to count number of images and windows
function counterFcn() {
	it_list = getList("image.titles");
	w_list = getList("window.titles");
	print("Number of images: " + it_list.length + ", Number of windows: " + w_list.length);
	
	if (it_list.length==0)
    	 print("No image windows are open");
  	else {
    	 print("Image windows:");
    	 for (i=0; i<it_list.length; i++)
        	print("   "+it_list[i]);
  	}
	print("");

	if (w_list.length==0)
    	 print("No non-image windows are open");
  	else {
    	 print("Non-image windows:");
    	 for (i=0; i<w_list.length; i++)
        	print("   "+w_list[i]);
  	}
	print("");
	
}
(Fiji Is Just) ImageJ 2.0.0-rc-65/1.52b; Java 1.8.0_66 [64-bit]; Windows 7 6.1; 93MB of 32002MB (<1%)
 
java.lang.NullPointerException
	at DeInterleave_.run(DeInterleave_.java:57)
	at ij.IJ.runUserPlugIn(IJ.java:222)
	at ij.IJ.runPlugIn(IJ.java:186)
	at ij.Executer.runCommand(Executer.java:137)
	at ij.Executer.run(Executer.java:66)
	at ij.IJ.run(IJ.java:302)
	at ij.macro.Functions.doRun(Functions.java:613)
	at ij.macro.Functions.doFunction(Functions.java:96)
	at ij.macro.Interpreter.doStatement(Interpreter.java:249)
	at ij.macro.Interpreter.doStatements(Interpreter.java:235)
	at ij.macro.Interpreter.run(Interpreter.java:118)
	at ij.macro.Interpreter.run(Interpreter.java:89)
	at ij.macro.Interpreter.run(Interpreter.java:100)
	at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:161)
	at ij.IJ.runMacro(IJ.java:139)
	at ij.IJ.runMacro(IJ.java:128)
	at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1096)
	at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1092)
	at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:1043)
	at net.imagej.legacy.IJ1Helper.runMacro(IJ1Helper.java:1092)
	at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:137)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
	at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

#4

@drchrisch

First thing…

This isn’t true exactly… If you check the definitions of the two function calls in the Built-in Macro Functions list, they say:

selectWindow(“name”)
Activates the window with the title “name”.

getImageID()
Returns the unique ID (a negative number) of the active image. Use the selectImage(id), isOpen(id) and isActive(id) functions to activate an image or to determine if it is open or active.

Honestly… I think your better bet is to use the follwoing combination of code calls:

id  = getImageID();
selectImage(id); // to activate that window

Lean on the unique ID … might be safer.

And yes - I’m getting that same error when running with setBatchMode(true); activated. There must be some issue with locating the correct image/window - must need it open/activated. Is the code you posted the actual code you are running for your work or just a ‘test’ script? Do you need to keep selecting the original image window before each command? What exactly is the workflow you are trying to execute?

We can either:

  1. have the most minimal example to test… only this Deinterleave issue.

OR

  1. you could post one of your datasets/images and the code you are using for us to try to recreate exactly as you have it… and try to improve the whole workflow.

eta


#5

Hi eta,

I created this unnecessarily long macro on purpose just to make sure that I actually can run a macro in batch mode. Also, getList(“image.titles”) reports essentially all hidden images from these commands.
The essential part would be just this “Deinterleave” command and trying it with the MRI stack sample is just fine. My impression is that “Deinterleave” kills the (hidden) input when called in batch mode.

Best
drchrisch


#6

Hi,

I get a similar problem.

setBatchMode(true);
run("Image Sequence...", "open=[/home/schmiedc/Desktop/data1/FMP_Docs/Projects/internalization_JE/NewTestInput/ 
run("Deinterleave", "how=3");

Gives me this error:

(Fiji Is Just) ImageJ 2.0.0-rc-68/1.52e; Java 1.8.0_172 [64-bit]; Linux 4.15.0-29-generic; 101MB of 21353MB (<1%)
 
java.lang.NullPointerException
	at DeInterleave_.run(DeInterleave_.java:57)
	at ij.IJ.runUserPlugIn(IJ.java:228)
	at ij.IJ.runPlugIn(IJ.java:192)
	at ij.Executer.runCommand(Executer.java:137)
	at ij.Executer.run(Executer.java:63)
	at ij.IJ.run(IJ.java:308)
	at ij.macro.Functions.doRun(Functions.java:613)
	at ij.macro.Functions.doFunction(Functions.java:96)
	at ij.macro.Interpreter.doStatement(Interpreter.java:249)
	at ij.macro.Interpreter.doStatements(Interpreter.java:235)
	at ij.macro.Interpreter.run(Interpreter.java:118)
	at ij.macro.Interpreter.run(Interpreter.java:89)
	at ij.macro.Interpreter.run(Interpreter.java:100)
	at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:161)
	at ij.IJ.runMacro(IJ.java:147)
	at ij.IJ.runMacro(IJ.java:136)
	at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1098)
	at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1094)
	at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:1045)
	at net.imagej.legacy.IJ1Helper.runMacro(IJ1Helper.java:1094)
	at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:137)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
	at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

#7

Well. seems that the issue is not solved yet (ImageJ 1.52b -> 1.52e). As suggested, there are other possibilities to split stacks/channels.


#8

If you look at this plugin’s source code (you can do this by typing “Deinterleave” in the search bar, and then click the Source button), you’ll see that the plugin was never compatible with the batch mode, as it uses the repaint() method of java.awt.Component directly, instead of just calling updateAndRepaintWindow() from the ImagePlus object:


If you want to try and have the time, it would be great if you can submit a pull request fixing this yourself.

I agree, you can de-interleave by converting to a hyperstack and then splitting the channels, for example, which should all be easily scriptable and compatible with the batch mode as well.