year = "2017-2018";

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(944,1077,954,1048,960,1036,970,1024,979,1014,995,1000,1010,1004,1032,1008,1036,989,1034,976,1033,956,1032,938,1026,927,1024,914,1029,906,1037,902,1050,890,1062,886,1097,887,1113,899,1123,912,1123,928,1131,937,1139,941,1139,957,1139,969,1144,986,1145,1005,1154,1017,1157,1029,1157,1050,1157,1065,1158,1075);
	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.00-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();
}
