Some weird behavior I came across while doing some thresholding and binary morphology in a macro:
running the binary Fill Holes operation causes the Fill command to always fill with ForegroundColor = (127,127,127). This can be dealt with by running setForegroundColor(255,255,255)again after Fill Holes, but it seems like that should not be necessary.
Here is a minimal example to demonstrate this behavior:
//closes images and sets colors
close("*");
setOption("BlackBackground", true);
setForegroundColor(255, 255, 255);
setBackgroundColor(0, 0, 0);
print(getValue("color.foreground"), getValue("color.background"));
//makes a donut
newImage("Untitled", "8-bit black", 100, 100, 1);
run("Specify...", "width=50 height=50 x=50 y=50 oval centered");
run("Fill", "slice");
run("Specify...", "width=25 height=25 x=50 y=50 oval centered");
run("Clear", "slice");
run("Select None");
rename("donut1");
//setForegroundColor(100, 100, 100);
//duplicates the donut
run("Duplicate...", "title=donut2");
run("Duplicate...", "title=donut3");
//setForegroundColor(100, 100, 100);
//fills the donut normally using "Fill"
selectWindow("donut1");
run("Specify...", "width=25 height=25 x=50 y=50 oval centered");
print(getValue("color.foreground"), getValue("color.background"));
run("Fill", "slice");
//fills the donut with "Fill Holes" but this causes the "Fill" command to now fill with 127
selectWindow("donut2");
run("Fill Holes"); //this seems to cause the problem...
print(getValue("color.foreground"), getValue("color.background"));
run("Specify...", "width=25 height=25 x=50 y=50 oval centered");
run("Fill", "slice");
//fills the donut after running "Fill Holes" but resets the fg color first, which fixes the problem
selectWindow("donut3");
run("Fill Holes"); //this seems to cause the problem...
setForegroundColor(255, 255, 255); //this will fix the problem
print(getValue("color.foreground"), getValue("color.background"));
run("Specify...", "width=25 height=25 x=50 y=50 oval centered");
run("Fill", "slice");
Here, donut1 gets filled in as expected with intensity 255, donut2 gets filled in with 127 because I run Fill Holes first. donut3 shows that one can correct this by running setForegroundColor again. It does not seem to matter what foregroundColor is actually set to, after running Fill Holes it always fills with 127. If I terminate the macro right after filling donut2 and try fill manually, it fills with 255 as expected.
What I also find a bit strange, not sure if it's related, is that inside of the macro setForegroundColor seems to be image specific. In the above example, if I run setForegroundColor(100, 100, 100) before duplicating, donut1 gets filled with 100 as expected. But if I run setForegroundColor(100, 100, 100) after duplicating, donut1 gets filled with 255. I was always under the impression that foregroundColor is a global property, which would be consistent with the behavior for manual image manipulation. But maybe I have misinterpreted this?
Anyway, thanks for your help!
best,
andrew
p.s. I also tested this on a new installation of IJ (FIJI) on a Windows machine, and I see the same behavior.
Update: these issues seems to be resolved if I use fill() instead of run("Fill", "slice"). I guess I will do that from now on, but I don't understand why the behavior would be different in this case.
OS: OSX 12.6.1 IJ: ImageJ2 v2.14.0/1.54f, build: c89e8500e4
Some weird behavior I came across while doing some thresholding and binary morphology in a macro:
running the binary
Fill Holes
operation causes theFill
command to always fill with ForegroundColor = (127,127,127). This can be dealt with by runningsetForegroundColor(255,255,255)
again afterFill Holes
, but it seems like that should not be necessary.Here is a minimal example to demonstrate this behavior:
Here, donut1 gets filled in as expected with intensity 255, donut2 gets filled in with 127 because I run
Fill Holes
first. donut3 shows that one can correct this by runningsetForegroundColor
again. It does not seem to matter whatforegroundColor
is actually set to, after runningFill Holes
it always fills with 127. If I terminate the macro right after filling donut2 and try fill manually, it fills with 255 as expected.What I also find a bit strange, not sure if it's related, is that inside of the macro
setForegroundColor
seems to be image specific. In the above example, if I runsetForegroundColor(100, 100, 100)
before duplicating, donut1 gets filled with 100 as expected. But if I runsetForegroundColor(100, 100, 100)
after duplicating, donut1 gets filled with 255. I was always under the impression thatforegroundColor
is a global property, which would be consistent with the behavior for manual image manipulation. But maybe I have misinterpreted this?Anyway, thanks for your help!
best, andrew
p.s. I also tested this on a new installation of IJ (FIJI) on a Windows machine, and I see the same behavior.