Re: Working with very large ROI sets
Posted by
MarSo on
Apr 19, 2009; 8:51pm
URL: http://imagej.273.s1.nabble.com/Working-with-very-large-ROI-sets-tp3692872p3692874.html
Thank you, Wayne... this is much better!
Best,
Nate
Wayne Rasband wrote
> Hello,
>
> I am trying to quantify the density of punctate fluorescent labeling
> in tissue slices. The end result of my routine is an set of ROIs that
> can contain a couple thousand individual regions (one for each
> possible label). I wrote the macro below to scan each ROI and remove
> it from the set if its mean intensity is below a threshold
> (vMeanCutOff). The macro works well but is VERY slow. It seems like
> everytime an ROI is checked, the entire set gets redrawn. If anyone
> has a suggestion for speeding this up (or a better way to do this to
> begin with) I'd greatly appreciate it!
>
> vMeanCutOff = 112.71
> j = 0
> run("Clear Results")
> while (j<roiManager("count")) {
> run("Clear Results");
> roiManager("Select", j);
> roiManager("Measure");
> vMean = getResult("Mean",0);
> if (vMean < vMeanCutOff) roiManager("Delete");
> if (vMean>= vMeanCutOff) j++;
> }
Run the macro in batch mode. This example macro runs ~100 times faster
in batch mode:
setBatchMode(true);
if (isOpen("ROI Manager")) {
selectWindow("ROI Manager");
run("Close");
}
run("Cell Colony (31K)");
run("Subtract Background...", "rolling=25 light");
setAutoThreshold();
run("Analyze Particles...", "size=0 circularity=0.00 exclude add");
cutOff = 175;
startTime = getTime;
j = 0;
print("Count (before): "+roiManager("count"));
while (j<roiManager("count")) {
roiManager("Select", j);
getStatistics(area, vMean);
if (vMean < cutOff) roiManager("Delete");
if (vMean>= cutOff) j++;
}
print("Count (after): "+roiManager("count"));
print(getTime-startTime+"ms");
-wayne