(Imagej)Statement cannot begin

Hello. I have a question today. I would appreciate your answer.
This time is the contents of imageJ. I am currently conducting research using imageJ. We use macros to automate analysis. So I entered the code as below.

open("/Users/..............................");
run("Color Threshold...");

// Color Thresholder 1.52k
// Autogenerated macro, single images only!
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run("HSB Stack");
run("Convert Stack to Images");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=0;
max[0]=255;
filter[0]="pass";
min[1]=0;
max[1]=255;
filter[1]="pass";
min[2]=0;
max[2]=254;
filter[2]="pass";
for (i=0;i<3;i++){
  selectWindow(""+i);
  setThreshold(min[i], max[i]);
  run("Convert to Mask");
  if (filter[i]=="stop")  run("Invert");
}
imageCalculator("AND create", "0","1");
imageCalculator("AND create", "Result of 0","2");
for (i=0;i<3;i++){
  selectWindow(""+i);
  close();
}
selectWindow("Result of 0");
close();
selectWindow("Result of Result of 0");
rename(a);
// Colour Thresholding-------------
run("Analyze Particles...", "  show=Outlines display clear");
a = eval("js","Analyzer.getResultsTable().getValueAsDouble(6,0)");
b = eval("js","Analyzer.getResultsTable().getValueAsDouble(7,0)");
parseInt(a);
parseInt(b);
c = "350";
a=a-c;
b=b-c;
close();
selectWindow(".......................");
close();
open("/Users/.........................");
makeOval(a, b, 700, 700);

I get an error in the part “a = a-c;”.
“Error: Statement cannot begin with ‘-’ in line 50:”
Why do you get such an error?

Thank you.

Dear Ryota,
I think you have several issues:

  • You’re trying a subtraction on variable of String type.
  • ‘eval’ returns a String representation of a double.
  • parseInt returns an Integer, but does not modify parameter in-place. Better use x=parseFloat(x) instead.
  • ‘c’ is declared as a String
  • you do not have to resort to evaluating javascript to access the results table. Use a=Table.get(columnName, rowIndex);
  • make sure you have the proper columns in your Results Table, by first calling “Set Measurements…” command (you can record it) before running "Analyze Particles…"

For that part of the code, I would rather write:

run("Set Measurements...", "area mean display redirect=None decimal=6");
run("Analyze Particles...", "  show=Outlines display clear");
column6Name = "Mean"; // adjust as needed
column7Name = "Area";
rowIndex = 0;
a = Table.get(column6Name, rowIndex);
b = Table.get(column7Name, rowIndex)
c = 350;
a=a-c;
b=b-c;
2 Likes

Thank you very much. I was able to solve the problem.