/* The way I wrote the integrated intensity type macros in the past was using the getHistogram() function which returns arrays containing the number of pixels (or voxels) from within a ROI (Region Of Interest). If the stack option is chosen, then the value through the entire stack is returned. But I rewrote the method using getRawStatistics(nPixels, mean, min, max, std, histogram); It only works on on slice of a stack at a time. v200 no error checking of any type. Question: What to do about background? Option1: Subtract a constant from the entire stack before running this macro, such as 110 if this is the dark level of the camera. Option2: The macro steps out n pixels from the ROI and measures the mean intensity of a band a few pixels wide. This is subtracted from the measurements before integrated intensity is calculated. Option3: A real flatfield correction. Probably not more precise than Option1 or 2 for biology but a lot more work. Option4: Tell me what you want and I can code it. */ var tab = " \t "; //=============================================== macro "integrated intensity of ROI on simple stack [q]"{ integratedintensityOnROIonStack(); } //=============================================== /* This function requires a stack and a closed ROI. */ function integratedintensityOnROIonStack() { run("Clear Results"); beginningslice = getSliceNumber(); intden = 0; columnmin = 9999999; columnmax = -1; for (i=1; i<=nSlices; i++) { setSlice(i); getRawStatistics(nPixels, mean, min, max, std, histogram); if (columnmin > min) columnmin = min; if (columnmax < max) columnmax = max; for (h=min; h<=max; h++) { intden = intden + (histogram[h] * h); // integrated density is sum of number of pixels of each value times the value } // calculate intden } // for each slice setSlice(beginningslice); print(getTitle() + tab + "min" + tab + "max" + tab + "intden"); print(nPixels + tab + columnmin + tab + columnmax + tab + intden); // first column is area, count of pixels selectWindow("Log"); // could be output to text file instead } // end integratedintensityOnROIonStack()