Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Fill Holes" changes "Fill" value inside of macro #221

Open
agclark12 opened this issue Aug 22, 2023 · 1 comment
Open

"Fill Holes" changes "Fill" value inside of macro #221

agclark12 opened this issue Aug 22, 2023 · 1 comment

Comments

@agclark12
Copy link

agclark12 commented Aug 22, 2023

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.

@agclark12
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant