year = "2018-2019";

inputDirSnaps="C:/Lucky Strike/TEMPO Analysis/Analysis/Preprocessing/"+year+"/snaps/";
list=getFileList(inputDirSnaps);
number_of_files = list.length;

for (i=0;i<number_of_files;i=i+1) {
	ROI_number =i;
	
	list=getFileList(inputDirSnaps);
	open(inputDirSnaps+list[ROI_number]);
	
	//run("Enhance Local Contrast (CLAHE)", "blocksize=49 histogram=256 maximum=3 mask=*None* fast_(less_accurate)");
	
	//setTool("polygon");
makePolygon(1203,1075,1190,1037,1181,1007,1180,985,1176,966,1164,954,1148,941,1139,921,1144,901,1152,890,1176,873,1184,860,1184,845,1165,816,1160,772,1197,770,1228,775,1266,802,1282,835,1301,867,1302,882,1305,902,1312,935,1317,959,1294,1010,1292,1045,1291,1077);
setBackgroundColor(0, 0, 0);
	run("Clear Outside");
	run("Split Channels");
selectWindow(list[ROI_number] + " (blue)");
close();
selectWindow(list[ROI_number] + " (red)");
close();
selectWindow(list[ROI_number] + " (green)");
	run("8-bit");
	run("Enhance Contrast...", "saturated=1 equalize");
	//setTool("text");
	run("Subtract...", "value=175");
	run("Make Binary");
	
	run("8-bit");
	saveAs("Jpeg", "C:/Lucky Strike/TEMPO Analysis/Analysis/Preprocessing/Zoanthid_get_number/Automated_zoanthid/"+year+"/zoanthid_"+list[ROI_number]);	
	run("Analyze Particles...", " size=5-infinity  circularity=0.25-1.00 show=Masks display clear add in_situ");
	saveAs("Results", "C:/Lucky Strike/TEMPO Analysis/Analysis/Preprocessing/Zoanthid_get_number/Automated_zoanthid/"+year+"/particles_"+list[ROI_number]+".csv");
	close();
}
