I am very new at using macros for image analysis. I would love any help troubleshooting my current problem. I have written a macro to calculate the sum of the pixel values in each of multiple ROIs in a single image. (I believe this is called the raw integrated density.) I attempted to make the macro only sum pixels above a certain threshold (50). However, I got strange results. With a threshold of 50, I got multiple ROIs with a value of “NaN,” which doesn’t make sense if RawIntDen is a sum. With a threshold of 0, I got no NaN values, but when I removed any threshold language entirely, I got values that in many cases were smaller than the 0 threshold values, which again makes no sense if RawIntDen is a sum! Am I misreading what RawIntDen is? Please help me fix my macro. Thanks!
//duplicate image and change to 8 bit
run("Duplicate...", "title=Duplicate.tif");
run("8-bit");
//Threshold image
run("Threshold...");
setThreshold(50, 255);
selectWindow("Threshold");
run("Close");
//Select all ROIs in the Manager
selectWindow("ROI Manager");
count=roiManager("count");
array=newArray(count);
for(i=0; i<count;i++) {
array[i] = i;
}
roiManager("Select", array);
//Calculate Raw Integrated Density for all ROIs
run("Set Measurements...", "integrated limit redirect=None decimal=0");
roiManager("Measure");
String.copyResults();