problem with batchmode

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with batchmode

JimmiB
Hi all,

I have a macro that runs as expected until I set
setBatchMode(true);
The It throws an exception

(Fiji Is Just) ImageJ 1.48s; Java 1.6.0_20 [64-bit]; Windows 7 6.1; 248MB
of 18395MB (1%)

java.lang.NullPointerException
at ij.plugin.Resizer.run(Resizer.java:35)
at ij.IJ.runPlugIn(IJ.java:169)
at ij.Executer.runCommand(Executer.java:131)
at ij.Executer.run(Executer.java:61)
at ij.IJ.run(IJ.java:269)
at ij.IJ.run(IJ.java:247)
at ij.macro.Functions.doRun(Functions.java:592)
at ij.macro.Functions.doFunction(Functions.java:89)
at ij.macro.Interpreter.doStatement(Interpreter.java:226)
at ij.macro.Interpreter.doBlock(Interpreter.java:598)
at ij.macro.Interpreter.doStatement(Interpreter.java:268)
at ij.macro.Interpreter.doFor(Interpreter.java:525)
at ij.macro.Interpreter.doStatement(Interpreter.java:250)
at ij.macro.Interpreter.doBlock(Interpreter.java:598)
at ij.macro.Interpreter.runFirstMacro(Interpreter.java:697)
at ij.macro.Interpreter.doStatement(Interpreter.java:259)
at ij.macro.Interpreter.doStatements(Interpreter.java:214)
at ij.macro.Interpreter.run(Interpreter.java:111)
at ij.macro.Interpreter.run(Interpreter.java:81)
at CLI.Refresh_Macros.runScript(Refresh_Macros.java:56)
at common.RefreshScripts.runScript(RefreshScripts.java:328)
at fiji.scripting.TextEditor$Tab$6.execute(TextEditor.java:1225)
at fiji.scripting.TextEditor$Executer$1.run(TextEditor.java:1785)

    The macro is below, it isn't the end of the world that it doesn't work,
but I have run into this problem a few times now and i wonder if i am doing
something wrong that causes this error.

Any feedback is appreciated,
Cheers,
James

//modified for islets
macro "Batch Align Stack"{
//run("Close All");
dir1 = getDirectory("Choose Source Directory 1 ");
dest1 = getDirectory("Choose Main Destination Directory ");
list=getFileList(dir1);
aligned=dest1+"aligned"+File.separator;
File.makeDirectory(aligned);
Dialog.create("Analysis Choices");
Dialog.addCheckbox("Delete excess frames?", false);
Dialog.addNumber("Last frame of interest:", 110);
Dialog.addCheckbox("Subtract Background", false);
  Dialog.show();
reducelength=Dialog.getCheckbox();
seqlength= Dialog.getNumber();
bgs=Dialog.getCheckbox();
//setBatchMode(true);
for (i=0; i<list.length; i++){
run("Close All");
clearROIs();
open(dir1+list[i]);
//name=substring(getTitle(), 18,30);
name=getTitle();
sl=lengthOf(name);
name=substring(name, 18,sl-4);
print(name);
rename(name);
open("\\\\pandora\\Volumes\\MetabolismDJ\\_CURRENT LAB
MEMBERS\\James\\Coor\\Result of Image005.tif");
rename ("BKG");
run("Split Channels");
selectWindow(name);
run("Split Channels");
imageCalculator("Subtract stack", "C2-"+name+"","C2-BKG");
imageCalculator("Subtract stack", "C1-"+name+"","C1-BKG");
run("Merge Channels...", "c1=C1-"+name+" c2=C2-"+name+" create");
Stack.getDimensions(w, h, c, s, f);
if(reducelength==1){
//run("Split Channels"); // add functionality for channels>2
setSlice(seqlength*2);
run("Delete slices after here");
run("Stack to Hyperstack...", "order=xyczt(default) channels="+c+" slices=1
frames="+seqlength+" display=Color");
}
if(bgs==1){
subtractBackground();
}
run("Select None");
clearROIs();
selectWindow("MAX");
run("Select None");
run("Median...", "radius=3");
setAutoThreshold("Triangle dark");
//setAutoThreshold("Huang dark");
run("Create Selection");
//run("Analyze Particles...", "size=2000-Infinity pixel
circularity=0.3-1.00 show=Nothing add");  //need to add functionality here
to deal with multiple ROIs
//roiManager("Select", 0);
run("To Bounding Box");
run("Enlarge...", "enlarge=10 pixel");
clearROIs();
roiManager("Add");
selectWindow(name);
roiManager("Select", 0);
run("Crop");
clearROIs();
run("Select None");
setSlice(1);
run("Split Channels"); // add functionality for channels>2
run("MultiStackReg", "stack_1=C1-"+name+" action_1=Align
file_1=C://Users//Loser//Desktop//TransformationMatrices.txt stack
stack_2=C2-"+name+" action_2=[Load Transformation File]
file_2=C://Users//Loser//Desktop//TransformationMatrices.txt stack
transformation=Translation save");
run("Merge Channels...", "c1=C1-"+name+" c2=C2-"+name+" create");
File.delete("C://Users//Loser//Desktop//TransformationMatrices.txt") ;
Stack.getDimensions(w, h, c, s, f);
  if (f>s){
  frames=f;
  }
  else{
  frames=s;
  }
  run("Select None");
run("Duplicate...", "title=TEMP duplicate channels=1-"+c+"
frames=1-"+frames+"");
run("Maximum...", "radius=2");
globalMin();
setThreshold(1, 16000);
run("Create Selection");
run("Enlarge...", "enlarge=-3 pixel");
run("Add to Manager");
close("TEMP");
close("MIN");
selectWindow(name);
roiManager("Select",0);
run("Crop");
run("Select None");
saveAs("Tiff", aligned+name);
rename(name);
//run("Close All");
clearROIs();
run("Z Project...", "projection=[Min Intensity]");
run("Median...", "radius=3");
rename("2C");
run("Z Project...", "projection=[Max Intensity]");
close("2c");
rename("min");
setAutoThreshold("Li dark");
run("Analyze Particles...", "size=50-Infinity circularity=0.3-1.00 add");
close("min");
selectWindow(name);
nROIs=roiManager("count");
print("nROIs="+nROIs);
Stack.getDimensions(w, h, channels, s, frames);
x=newArray(frames);
y=newArray(frames);
for(n=0; n<nROIs; n++){
//selectWindow(name);
roiManager("Select", n);
//header=call("ij.plugin.frame.RoiManager.getName", n);
for(s=1; s<=frames+1; s++){ //for each frame
getStatistics(area);
setResult(name+"-area"+n, s-1, area);
for(c=1; c<=channels; c++){     // for each channel
Stack.setPosition(c, 1, s);
getStatistics(area, mean);
print(mean);
setResult(name+"_C"+c+"_"+n, s-1, mean);
updateResults();
} //end for each channels
}// end for each frame
}//end for each ROI
run("Close All");
selectWindow("Results");
saveAs("txt", aligned+name+"_Results");
run("Clear Results");
} //end for each file
 }
// end macro
clearROIs();

function subtractBackground(){
clearROIs();
name=getTitle();
globalMax();
run("Gaussian Blur...", "sigma=3");
setAutoThreshold("MinError dark");
run("Create Selection");
run("Make Inverse");
run("Enlarge...", "enlarge=-10 pixel");
roiManager("Add");
selectWindow(name);
run("Clear Results");
//run("Set Measurements...", "  median redirect=None decimal=3");
for(i=0; i<=nSlices()-1; i++){
setSlice(i+1);
roiManager("Select", 0);
//run("Measure");
//median=getResultString("Median", i);
getStatistics(a, bkg);
run("Select None");
run("Subtract...", "value="+bkg+"");
}
}
function clearROIs(){
if(isOpen("ROI Manager")){
if (roiManager("count")>0) {
roiManager("Reset");
}
}
}
function globalMax(){
Stack.getDimensions(w, h, c, s, f);
if (f>s){
  frames=f;
  }
  else{
  frames=s;
  }
run("Z Project...", "start=1 stop=frames projection=[Max Intensity]");
rename("MAX_colour");
run("Z Project...", "start=1 stop=c projection=[Average Intensity]");
rename("MAX");
close("MAX_colour");
}
function globalMin(){
Stack.getDimensions(w, h, c, s, f);
if (f>s){
  frames=f;
  }
  else{
  frames=s;
  }
run("Z Project...", "start=1 stop=frames projection=[Min Intensity]");
rename("MIN_colour");
run("Z Project...", "start=1 stop=c projection=[Min Intensity]");
rename("MIN");
close("MIN_colour");
}
}






*Dr James Burchfield*
The Garvan Institute of Medical Research
384 Victoria Street
Darlinghurst, NSW, 2010
Australia

Email: [hidden email]
Phone:+61 2 92958229
Web: *www.garvan.org.au <http://www.garvan.org.au>*

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: problem with batchmode

dscho
Hi James,

On Thu, 20 Mar 2014, James Burchfield wrote:

> I have a macro that runs as expected until I set
> setBatchMode(true);
> The It throws an exception
>
> (Fiji Is Just) ImageJ 1.48s; Java 1.6.0_20 [64-bit]; Windows 7 6.1; 248MB
> of 18395MB (1%)
>
> java.lang.NullPointerException
> at ij.plugin.Resizer.run(Resizer.java:35)
> [...]

That line reads:

        Rectangle r = ip.getRoi();

suggesting to me that maybe there was a 0-slice image.

>     The macro is below, it isn't the end of the world that it doesn't
>     work, but I have run into this problem a few times now and i wonder
>     if i am doing something wrong that causes this error.

Your macro is very long and assumes certain files and directories to be
present. Under normal circumstances, I would try to find half an hour to
reduce it to a minimal example, but today I simply do not have time.

Would you mind reducing the macro to the bare minimum displaying the
error? I would then finagle a gap into my schedule to debug and fix it.

Ciao,
Johannes

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html