Changing original results labels from one window based on measurements from another window

I am trying to write a macro that analyzes muscle fiber cross sectional area and determines fiber type. The fiber areas are identified on one channel based on a membrane stain. This is the window where all ROIs are created. Fiber types are determined by specific fiber-type stains in the other channels. So I have 4 channels: membrane, type I, Type IIa and type IIb.

Determining cross sectional area is easy enough, but in order to determine fiber type I have to overlay each ROI from the membrane channel over each fiber-type channel, measure the grayscale intensity of each ROI, and if the mean intensity if high enough then the fiber qualifies as that particular fiber type and is named accordingly. The membrane stain generates about 100 ROIs in an image, each ROI is a fiber who’s fiber type is determined in the other channels. My end goal is to have a results section that lists each ROI’s fiber type and cross sectional area.

My problem is that I just can’t get the code to work. Below is a section of the macro where I am trying to overlay and measure the mean grayscale intensity on a fiber type channel (MHCI). When I run this code however, all area and grayscale measurements are taken accurately, but nothing is being relabeled. Help!

run("From ROI Manager");
run("Set Measurements...", "area mean display add redirect=None decimal=3");
run("Clear Results");
nCount = roiManager("count");
for (i = 0; i < nCount; i++) {
	roiManager("select", i);
	Mean = getResult("mean", i);
	if (Mean > 7500) {
	roiManager("select", i);
	roiManager("rename", "I");

Hi LyleB,

in terms of debugging your macros use print() statements as liberal as possible and try to always see if the macro measures, returns and runs as you want it.

Thus if you have a if…else statement see if it is actually entering it by:
print("Mean greater than 7500")

Also see if the variable Mean is actually containing stuff by printing its value:
print("ROI has mean of " + Mean);

With if…else conditions also always use an else statement with a print so that you see when it does not enter your condition.

As for your bug. I suspect the “mean” in the getResults should be upper case. Like so:

Mean = getResult("Mean", i);

You will catch those bugs only if you use print statements.


Thanks for your help. I’ve been testing my macro by running it in conjunction with the rest of the code, and no errors or debugging windows show up (they did when I capitalized “mean”, so that wasn’t the bug). But you’re right in that I have no idea if the variable “Mean” has anything or if its picking up any means greater than 7500.