Hi @dlite-x,
If I read your post correctly, you already have a list of ROIs (or an overlay or something) and you want to find a way to set âhighâ pixels to zero whilst looping through your existing ROIs, and without creating any unecessary new ROIs.
However, is the threshold the same for all the images in the stack(s) and across all ROIs? If so, perhaps consider ignoring the ROIs for the high-pixel capping/zeroing. In that case, you can cycle through the stack and apply the same operation to all images and with minimal ROI handling. I think this macro follows your precise instructions and is an example of ignoring the ROIs:
//option 1
setBatchMode("hide");
setThreshold(210, 255); //put your thresholds here
for (i = 1; i <= nSlices; i++) {
setSlice(i);
run("Create Selection");
run("Set...", "value=0");
run("Select None");
}
resetThreshold;
setBatchMode("exit and display");
I also enclosed the code in a batchmode block, for likely speedup (may or may not be noticeable depending on the size of your images). You can then do your ROI analysis on the already modified images⌠or just after each slice is changed within the same loop, if you want to cut back on overall loop iterations.
This is another potential solution, which doesnât do exactly waht you ask, but I feel may still mitigate against high-pixel atefacts:
//option 2
run("Remove Outliers...", "radius=2 threshold=50 which=Bright stack");
Itâs also my favourite, as itâs simple and should be very fast. You may also need to play with the settings, to match your needs (although, that goes for all my answers here really).
Finally, if, for whatever reason, you do only want to change the pixels within each ROI, this slightly more convoluted code might work for you:
//option 3
setBatchMode("hide");
originalImageTitle = getTitle();
for (j = 0; j < roiManager("count"); j++) {
roiManager("select", j);
run("Duplicate...", "title=temp");
//option 1 or 2 here... option 1 is used in this example, below
setThreshold(210, 255); //put your thresholds here
run("Create Selection");
run("Set...", "value=0");
run("Restore Selection");
resetThreshold;
run("Copy");
close("temp");
selectWindow(originalImageTitle);
run("Paste");
}
run("Select None");
setBatchMode("exit and display");
Obviously, the thresholds that I chose for all âsolutionsâ above are completely arbitrary. I was also manipulating 8-bit image stacks in my testing. I also assumed that your ROIs are in the ImageJ ROI manager. I didnât know all the particulars of your workflow, but hopefully the principals I outlined should be easy enough to adapt to your own data.
I also fully acknowledge that there may be an even easier and more complete solution that I do not know of or did not link with your question, that some other clever person in this forum may embarrass me by posting
. In fact, given your original explanation, you may have already considered any or all of the above and want something more elegant again! Apologies if that is the case.
Kind regards.