"Fill Holes" changes "Fill" value inside of macro
- Dominant language
- Java
- Stars
- 786
- Forks
- 267
- PR merge metrics
- No merged PRs in 30d
Description
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 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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by running the minimal macro and tracing the Fill Holes and Fill commands, focusing on how foreground color is retained across images. Compare the macro output with manual filling; done means Fill Holes no longer changes the subsequent Fill value, while the documented reproduction passes on macOS and Windows.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100