Login  Register

Re: code to open, display, modify, pause, go back to directory

Posted by wainsw1 on Jan 18, 2013; 1:46am
URL: http://imagej.273.s1.nabble.com/help-with-Batch-Merge-of-2-channel-image-sequence-tp5001242p5001462.html

Klara,

This may be a little late, however I will post this with the hope that future ImageJ-ers who stumble across this forum with a similar problem find the solution they seek.  In short, your macro uses the code "setBatchMode(true);" and, according to ImageJ documentation,

setBatchMode(arg)

If arg is true, the interpreter enters batch mode and images are not displayed, allowing the macro to run up to 20 times faster. If arg is false, exits batch mode and displays the active image in a window. ImageJ exits batch mode when the macro terminates if there is no setBatchMode(false) call. Note that a macro should not call setBatchMode(true) more than once.
This means that, once you're in "Batch Mode," no images will be displayed until you set the argument (arg) to be false.  

Also, to cut down on some steps that you go through, I suggest changing the script as follows:

dir = getDirectory("Choose a Directory ");
//I excluded the setBatchMode, as the following steps occur so quickly, that they probably won't be seen anyway
//Feel free to add it, however you must setBatchMode(false) when you want to interact with the image
list = getFileList(dir);

for (i=0; i<list.length; i++) {
showProgress(i, list.length);
open(dir+list[i]);

title = getTitle();
run("Slice Remover", "first=1 last=3 increment=1");
//This will remove all slices but the fourth
//Can also be found in  Image >> Stacks >> Tools >> Slice Remover
//Note that I am using the Fiji Build of ImageJ, so this may be different than yours.  
//If you do not have the "Slice Remover" plugin, download and place it in your ImageJ plugins folder

setAutoThreshold("Default dark");
run("Convert to Mask");

run("Fill Holes");
run("Watershed");
//setTool("wand");

run("Set Measurements...", "area mean perimeter display add redirect=None decimal=3");
run("wait For User");
close;}


With these corrections, the image should appear.  

Hope this helps!
Barrett