introvoyz041's picture
Migrated from GitHub
5ad11ec verified
// Open this macro from ImageJ
// Change the input_dir: a directory which contain 8 images of same wavelength.
// or a big folder image, and define the pattern of image as image_fn below.
// then run entire macro: run macro from menu bar or Cmd + R in mac, ctrl + R in other os sys I think.
input_dir="/Users/hoatran/Documents/BCCRC_projects/merfish/XP2059_FOV25/";
output_dir=input_dir+"counting_spots/";
if(!File.exists(output_dir))
File.mkdir(output_dir);
for (r=1; r<=8; r++) {
//r=8;
image_fn="merFISH_0"+r+"_025_05.TIFF";
open(input_dir+image_fn);
short_name = substring(image_fn,0,indexOf(image_fn,'.TIFF'));
run("8-bit");
run("Enhance Contrast...", "saturated=0.2 normalize");
run("Convolve...", "text1=[-1 -1 -1 -1 -1\n-1 -1 -1 -1 -1\n-1 -1 24 -1 -1\n-1 -1 -1 -1 -1\n-1 -1 -1 -1 -1\n] normalize");
//open(input_dir+"demo/mask.tif");
selectWindow(image_fn);
//imageCalculator("AND create", image_fn,"mask.tif");
//selectWindow("mask.tif");
//close();
//selectWindow("Result of "+image_fn);
//selectWindow(image_fn);
nBins = 256;  
row = 0;
getHistogram(values, counts, nBins);
for (i=250; i<nBins; i++) {
     setResult("Value", row, values[i]);
     setResult("Count", row, counts[i]);
     row++;
}
updateResults();
saveAs("Results",output_dir+short_name+"_hist.csv");
//selectWindow("Result of "+image_fn);
selectWindow(image_fn);
saveAs("Tiff",output_dir+image_fn);
run("Close All");
//selectWindow(image_fn);
//close();
run("Close All");
list = getList("window.titles");
if(list.length>0){
for (i=0; i<list.length; i++){
winame = list[i];
print(winame);
selectWindow(winame);
run("Close");
}
}
}