My macro works in Ubuntu but not on Windows... help please!

Hi! Thanks to all the active users on the forum - I am new to ImageJ and have found previous posts very helpful as I have put together my own macro.

I am trying to write a macro that will threshold images to a selected value. I have confocal microscopy images that exist as stacks with one image per channel, and with the help of previous posts I have written a macro that cycles through the files, and then through the stacks, using the Colour Threshold macro to threshold to my value of interest. The macro then takes an 8-bit copy of the image and measures it. This works great on my own laptop (running the most recent release of ImageJ in Ubuntu 16.04), although I haven’t been able to wrap the macro in batch processing code, and instead have been relying on the Process --> Batch --> macro function in the GUI.

However, when I try to run the same macro in the Batch Process window on the lab computer (running Windows) it doesn’t work- or at least it works but does not generate the same values! To make matters worse when I manually threshold the images and measure them, I get values that correspond to the macro in linux – but the results generated by the macro in Windows do not correspond to my manual measurements.

I don’t understand what’s happening, as my code is the same in both cases. Could it be a setting in ImageJ? any help much appreciated.

Sorry for my inelegant code, I’m new at this…

macro "TOGETHER" {
my_threshold= 37; // SET THIS NUMBER
print_name=getTitle;


StackID=getImageID(); 
     directory=getDirectory("image");
     name=getTitle;
     Slices=nSlices;
     //print("\\Clear"); 




for (k=0; k<Slices; k++) {
         //print("begin loop slice "+(k+1)); 
         selectImage(StackID); 
         setSlice(k+1); 




//imgName=getTitle(); 
run("Duplicate...", "title=1.tif"); 




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]=my_threshold;
max[2]=255;
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(""+print_name+"-"+(k+1));


run("Create Selection"); 
run("Set Measurements...", "area limit display redirect=None decimal=3");
run("Measure");


close();


area_measurement = getResult("Area");
print(""+print_name+"; "+(k+1)+"; "+my_threshold+";"+area_measurement+";");
}

You could try running Edit :arrow_forward: Options :arrow_forward: Reset on both machines to reset the settings back to defaults. Then see if the results match on both machines after that.

See also the Troubleshooting page of the wiki. (It is down right now, but will be back up within a couple of days.) It has an entry on what to do if two computers produce different results.

Thanks very much!

In true newb fashion I seem to have stumbled across a possible solution… right after giving up and posting here!

I modified

run(“Create Selection”);
run(“Set Measurements…”, “area limit display redirect=None decimal=3”);
run(“Measure”);

to

run("Invert"); run("Create Selection"); run("Set Measurements...", "area limit display redirect=None decimal=3"); run("Measure");

and it works on the Windows machine! Not sure why it was already working on Linux but there you go. Hope this helps someone else!

Check Process :arrow_forward: Binary :arrow_forward: Options… and see whether “Black background” is checked on each machine. I’m guessing the two settings differ.

2 Likes

BINGO!!

Thanks for your help. I really appreciate it.

1 Like