Select ROI over specific threshold

Hey,

I use ImageJ/Fiji and have a 2D image and around 300 ROIs in the ROI manager.
I measured the intensities of all ROIs and want to keep/select all ROIs which have a mean intensity over a specific threshold I set or remove all ROIs under this threshold. I could not find any solution and am relatively new to ImageJ/Fiji. Do you have any ideas on how to solve the problem?

Hi @MarcD
Test this macro:

run("Blobs (25K)");
run("Duplicate...", " ");
setAutoThreshold("Default");
//run("Threshold...");
//setThreshold(126, 255);
setOption("BlackBackground", true);
run("Convert to Mask");
run("Set Measurements...", "mean display scientific redirect=None decimal=9");
run("Analyze Particles...", "display exclude add");
close("Results");
selectWindow("blobs.gif");
roiManager("Show All without labels");
n=roiManager("count");
a = newArray();
for(i=0;i<n-1;i++) {
roiManager("Select", i);
run("Measure");

if(getResult("Mean",i)<190)
{
a = Array.concat(a, i);

}}
  Array.print(a);
roiManager("Select", a);
roiManager("Delete");
//-----

roiManager("Set Fill Color", "blue");
roiManager("Show None");
roiManager("Show All");

Hi Marc,
By going through the list of ROIs in reverse order you can avoid the need to create an array to delete the unwanted ROIs as deleting an ROI doesn’t affect the index of the ROIs that haven’t been processed yet. Below is an edited version of Mathew’s code that uses this approach and produces the same result.
Cheers,
Volko

run("Blobs (25K)");
run("Duplicate...", " ");
setAutoThreshold("Default");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Set Measurements...", "mean display scientific redirect=None decimal=9");
run("Analyze Particles...", "display exclude add");
close("Results");
selectWindow("blobs.gif");
roiManager("Show All without labels");
n=roiManager("count");
for(i=n-1;i>0;i=i-1) {
	roiManager("Select", i);
	run("Measure");
	if(getResult("Mean",nResults-1)<190){
		roiManager("Delete");
	};
};
roiManager("Set Fill Color", "blue");
roiManager("Show None");
roiManager("Show All");
2 Likes

@Volko
Very nice initiative. I never think about this thing.
Thank you.

Thanks to @Volko and @Mathew. That works fine with my data set!

1 Like