year = "2015-2016";

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("Smooth");
	run("Smooth");
	
	//setTool("polygon");
makePolygon(948,1078,948,1056,938,1030,930,1018,938,988,940,972,942,966,954,960,962,948,966,942,972,940,986,944,1000,948,1002,946,1012,936,1020,922,1064,906,1074,912,1104,920,1120,932,1118,954,1118,970,1114,988,1114,1008,1122,1024,1126,1054,1146,1076,1150,1078);
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=190");
	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...", "  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();
}
