year = "2014-2015";

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+4) {
	ROI_number =i;
	
	list=getFileList(inputDirSnaps);
	open(inputDirSnaps+list[ROI_number]);
	
	
	run("Smooth");
	run("Smooth");
	
	//setTool("polygon");
makePolygon(1196,969,1231,979,1240,1005,1272,1023,1298,1046,1304,1065,1314,1077,1116,1077,1100,1064,1097,1056,1099,1045,1113,1042,1126,1030,1135,1013,1151,994,1155,978);
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();
}
