This macro goes through regions of interest drawn in XY on a stack of 8 or 16 bit grayscale images and reports the mean
intensity of the top n pixels per region per slice.
The purpose is to look at change of intensity through time and allows for regions to be drawn larger than the feature of interest
so that some movement of the sample is acceptable. As long as two features of interest do not intersect during the duration of the
sequence, this method works well.
Variable "topn" contains the number of brightest pixels to be averaged and reported. topn=1 is the equivalent as measuring the maximum
intensity pixel.

Image must be a file already saved to disk because the data are output to a text file and needs the path.
To decide where to draw the regions, do a maximum pixel projection and darw ROIs that completely contain each feature.
Add each region to the ROI Manager.
Save the ROI manager using the macro "Save ROI Manager [F7]".
Select the original movie and run macro "Measure top n pixels mean intensity [q]".

Before running, you may want to do a median 1x1 filter onthe stack to reduce noise.

For each ROI, the intensities at each slice are measured.
There is an outer loop, for each roi, and an inner loop, for each slice.
Within these loops, a measurement method may be inserted.

The first column reports the frame number.
If the time info were in the metadata of the file, then instead of reporting the frame number, the time could be reported.


Important note:
To speed this up a little, the macro assumes you cannot have a pixel value greater than 16383.  If this is wrong, then the code to change is uncommenting the first line and deleting the second line.
//  currentPosition = counts.length-1;    // for full 16 bits this should be set to 65536
  currentPosition = 16384;  // used to speed up when max cannot fill all 16 bits, use the max possible value +1