Modifying My Macro's Results/Summary and Applying it to a Batch of Images

batch-processing
analyze-particles
color-analysis
macro
fiji
Tags: #<Tag:0x00007fd547f4ece0> #<Tag:0x00007fd547f4e9e8> #<Tag:0x00007fd547f4e678> #<Tag:0x00007fd547f4e290> #<Tag:0x00007fd547f4df98>

#1

Hello, novice FIJI/ImageJ user here. I also have little coding experience. I have two errors with my macro. The code is below.

This code essentially opens up an image from the directory, copies it, highlights one of the colors in the mage, analyzes that color (turns the highlight to black by default), saves the results adds some filter to change the color back to the one it highlighted (or something similar).

  1. I am trying to save the results and summary in a separate folder. At the moment, my code is properly saving the results for each color (excel/csv file). However, the general summary of all the colors will not save properly. The problem is, the line of code/command is the same for both results and summary. I used the macro recorder and the recorder put the same line of code. Therefore, whenever the Summary excel file is saved, it is just the results of the last color highlighted. If someone can please help me with this, it would be much appreciated. Currently, I am just manually saving the Summary, but my goal is to make it automatic.

  2. If you look at the code, I assigned an object to the specific image in the directory. I think that because of this, the batch processing tool does not work as it should. Also, I think it does not work properly because my code forms multiple images from one image and the batch processing is one to one. If someone knows how to modify my code to apply to a folder of multiple images, please let me know. Thank you.

Below the line is the code. I am using the IJ1 Macro language.
–___–

x="C:\\Users\\srumalla\\Documents\\SIDDARTH RUMALLA\\Imaging Researching Project 2017\\Other\\Present\\Overall\\Sample Images\\Batch 2\\20170608_230.tif";
//Done
//Opening the ORIGINAL image from the directory and renaming it and setting scale & measurements
open(x);
run("Set Scale...", "distance=6.8 known=1 pixel=1.33333 unit=micron global");
run("Set Measurements...", "area centroid center perimeter shape area_fraction display redirect=None decimal=3");
a=getTitle();
a="Original Colored Image "+1;
rename(a);
//Done
//Applying a BLACK color filter and renaming it and analyzing it and color it (already done for black)
open(x);
b=getTitle();
min=newArray(3);
max=newArray(3);
filter=newArray(3);
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]=60;
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");
b="Black Highlight "+1;
rename(b);
selectWindow("Black Highlight 1");
run("Analyze Particles...", "display clear summarize record add");
roiManager("Show None");
saveAs("Results", "C:\\Users\\srumalla\\Documents\\SIDDARTH RUMALLA\\Imaging Researching Project 2017\\Other\\Present\\Overall\\Sample Images\\Data from Batch 2\\BlackResults.csv");
//Done
//Applying a WHITE color filter and renaming it and analyzing it and color it
open(x);
c=getTitle();
min=newArray(3);
max=newArray(3);
filter=newArray(3);
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]=79;
filter[1]="pass";
min[2]=239;
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");
c="White Highlight "+1;
rename(c);
run("Analyze Particles...", "display clear summarize record add");
roiManager("Show None");
saveAs("Results", "C:\\Users\\srumalla\\Documents\\SIDDARTH RUMALLA\\Imaging Researching Project 2017\\Other\\Present\\Overall\\Sample Images\\Data from Batch 2\\WhiteResults.csv");
selectWindow("White Highlight 1");
run("16_colors");
//Done
//Applying a BROWN color filter and renaming it and analyzing it and color it
open(x);
d=getTitle();
min=newArray(3);
max=newArray(3);
filter=newArray(3);
run("HSB Stack");
run("Convert Stack to Images");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=15;
max[0]=98;
filter[0]="pass";
min[1]=70;
max[1]=255;
filter[1]="pass";
min[2]=95;
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");
d="Brown Highlight "+1;
rename(d);
run("Analyze Particles...", "display clear summarize record add");
roiManager("Show None");
saveAs("Results", "C:\\Users\\srumalla\\Documents\\SIDDARTH RUMALLA\\Imaging Researching Project 2017\\Other\\Present\\Overall\\Sample Images\\Data from Batch 2\\BrownResults.csv");
run("mpl-inferno");
//Done
//Applying a TURQUOISE filter and renaming it and analyzing it and color it
open(x);
e=getTitle();
min=newArray(3);
max=newArray(3);
filter=newArray(3);
run("HSB Stack");
run("Convert Stack to Images");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=103;
max[0]=141;
filter[0]="pass";
min[1]=0;
max[1]=255;
filter[1]="pass";
min[2]=160;
max[2]=228;
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");
e="Turquoise Highlight "+1;
rename(e);
run("Analyze Particles...", "display clear summarize record add");
roiManager("Show None");
saveAs("Results", "C:\\Users\\srumalla\\Documents\\SIDDARTH RUMALLA\\Imaging Researching Project 2017\\Other\\Present\\Overall\\Sample Images\\Data from Batch 2\\TurquoiseResults.csv");
run("Cyan");
//Done
//Applying a PINK filter and renaming it and analyzing it and color it
open(x);
f=getTitle();
min=newArray(3);
max=newArray(3);
filter=newArray(3);
run("HSB Stack");
run("Convert Stack to Images");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=230;
max[0]=255;
filter[0]="pass";
min[1]=142;
max[1]=255;
filter[1]="pass";
min[2]=0;
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");
f="Pink Highlight "+1;
rename(f);
run("Analyze Particles...", "display clear summarize record add");
roiManager("Show None");
saveAs("Results", "C:\\Users\\srumalla\\Documents\\SIDDARTH RUMALLA\\Imaging Researching Project 2017\\Other\\Present\\Overall\\Sample Images\\Data from Batch 2\\PinkResults.csv");
run("Magenta");
//Done
//Applying a SILVER filter and renaming it and analyzing it and color it
open(x);
g=getTitle();
min=newArray(3);
max=newArray(3);
filter=newArray(3);
run("HSB Stack");
run("Convert Stack to Images");
selectWindow("Hue");
rename("0");
selectWindow("Saturation");
rename("1");
selectWindow("Brightness");
rename("2");
min[0]=36;
max[0]=255;
filter[0]="pass";
min[1]=0;
max[1]=143;
filter[1]="pass";
min[2]=206;
max[2]=224;
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");
g="Silver Highlight "+1;
rename(g);
run("Analyze Particles...", "display clear summarize record add");
roiManager("Show None");
saveAs("Results", "C:\\Users\\srumalla\\Documents\\SIDDARTH RUMALLA\\Imaging Researching Project 2017\\Other\\Present\\Overall\\Sample Images\\Data from Batch 2\\SilverResults.csv");
run("Rainbow RGB");
//Done (MUST MANUALLY SAVE SUMMARY)