/* 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. Instructions: 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. */ var topn = 20; var tab = " \t "; macro "Measure top n pixels mean intensity [q]" { run("Set Measurements...", "mean min stack limit display redirect=None decimal=2"); path = getDirectory("image"); title = getTitleStripExtension(); s = nSlices(); output = newArray(s); for (slice=0; slice 8) bins = 65536; else bins = 256; getHistogram(dummy0, counts, bins); // use counts numberCountedSoFar = 0; // currentPosition = counts.length-1; // for full 16 bits currentPosition = 16384; // used to speed up when max cannot fill all 16 bits sum = 0; do { if ((numberCountedSoFar + counts[currentPosition]) > n) x = n - numberCountedSoFar; else x = counts[currentPosition]; numberCountedSoFar = numberCountedSoFar + x; sum = sum + (x * currentPosition); currentPosition--; } while (numberCountedSoFar < n); mean = sum / n; return mean; } macro "test image" { // intensities = newArray( // 1000, 1000, 1000, 1000, 1000, 1000, 2000, 2100, 2200, 2300, 900); intensities = newArray( 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000); Array.getStatistics(intensities, min, max, mean, stdDev); print(min, max, mean); newImage("image", "16-bit black", 256, 256, 1); cornerx = 10; cornery = 10; for (x=0; x