// Median_FITS_Image.txt
//
// FVH (2008-09-07)

ns = nSlices();
if (ns <= 1) exit("ERROR: Median FITS Image only works with a stack!");

name = "MEDIAN FITS IMAGE";
title = getTitle();
setSlice(1);
label1 = getInfo("slice.label");
setSlice(ns);
labeln = getInfo("slice.label");

run("Z Project...", "projection=Median");
run("Enhance Contrast", "saturated=0.5");
rename(name);

run("Copy FITS Header", "from=["+title+"] to=["+name+"] history=[Median of "+ns+" images from the stack "+title+":]");
run("Write FITS Header", "image=["+name+"] type=[HISTORY] comment=[... from "+label1+" to "+labeln+"]");
