ImageJ macro recording of threshold

Hello
@haesleinhuepf @Wayne
When macro recording the [ Image > Adjust > Threshold ] we get

setAutoThreshold("Default dark");
//run("Threshold...");
//setThreshold(29, 255);
run("Convert to Mask");

…where the setThreshold is commented, which is bad, because this is the actual threshold values that we used. Could that be changed?

Hi @Christian_Tischer,

if this line would not be commented, the term “autoThreshold” would no longer describe what we do. Thus, I recommend not changing anything as automatic thresholding should be preferred over manual constant thresholding.
However, if it makes sense to use constant thresholds in your particular project, why not un-commenting the line?

Cheers,
Robert

1 Like

If you open the “Set” action in the threshold dialog and confirm it the value is uncommented.

2 Likes

I think if people manually change the values by moving the sliders they clearly indicate that they want to override the suggested auto-threshold. What do you think?

Maybe I was not clear here: The code I posted above is from recording [ Image > Adjust > Threshold ] and not from [ Image > Adjust > Auto Threshold ].

1 Like

(whisper) I’ve seen people manually setting the threshold bar and afterwards measuring signal intensity range.

I strongly vote for automatic thresholds whenever possible and reasonable. In advance some image normalisation, background subtraction, etc. might help as well. Wanna share an example image with us? (-:

1 Like

This can be discussed, but it really is not the point :slight_smile:
If there exist a manual threshold command I strongly feel it should be recorded as such (and not secretly overriding the users choice, because of a feeling that one knows better)!

1 Like

The problem is: when you run Image > Adjust > Threshold, the first thing that gets executed is an automatic threshold, and that is what gets recorded.

Recording every single slider change would very quickly spam your recorder panel, no? I suggest educating users (maybe simply by recording a comment telling so) to use the Set button when they want the actual value recorded as a fixed value.

2 Likes

I stumbled across this myself recently in the following context:
I often tell users to turn on the macro-recorder not specifically to record a macro for automation but to create a step-by-step protocol of what they are doing. In that context, the need to perform an additional step (even just pressing Set) to make sure the action actually shows up in the protocol can lead to the user being unable to re-trace their steps.

I see the practical problem with the slider mentioned by @imagejan as well though. Would the logging be triggered once the slider is released or for every little nudge while it’s being dragged?
(I.e. are we talking about a few lines being logged while the user tries different values or hundreds of lines?)

2 Likes

That’s true! In fact, now I see that the current Threshold UI somewhat is a beast, mixing up auto threshold and manual threshold and thus is hard to record, hard to control for inexperienced users, and hard to comprehend properly. Sorry, for feeling so strongly about it, but I can really see how one does bad science using this UI, because there are so many confusing buttons and options.

What about cleaning up the user interface like this:

  • Manual Threshold
  • Auto Threshold
  • Auto Local Threshold

For legacy reasons, one probably must leave the old Threshold option in there, but at least I strongly feel we should really add one simple proper Manual Threshold UI element.

What do you think?

@ctrueden

1 Like

I would just record the settings at the moment the user is pressing [ Apply ], wouldn’t that work?

IMHO the user should be forced to do an additional step to make him think about what he is doing. So either he uncomments the // setThreshold(50, 100); and knows that he is introducing a manual constant threshold or he clicks the Set button. It’s kind of a confirmation that he really wants to use a subjective threshold… So I think it’s good as it is. And now I stop annoying and show myself out. :wink:

1 Like

Seems like we have to agree to disagree here :slight_smile:

1 Like

Speaking from experience: any change we make to very common core functionality in ImageJ will be met with complaints. I agree with @Christian_Tischer that a good way to think about such changes is: what impact will it have on the way people work? Will it encourage good workflows, or bad workflows, and how + why? I also agree that existing functionality should be left in place—at minimum, existing macros must still work the way they did before. It’s a tall order, and likely means that the way thresholding works in ImageJ won’t change any time soon. There are lots of other bigger fish to fry right now.

My feeling is that the thresholding UI should be improved as part of a larger UI overhaul. Maybe that is someone rescuing and continuing the ImageJFX project; maybe that is another entirely new UI; or maybe just integrating ImageJ features with other existing UIs. Or all of the above. Those projects are outside the scope of what I can achieve at LOCI right now, but I’m very supportive and enthusiastic if another group wants to get involved in those directions.

1 Like

@ctrueden
Would just adding a simple manual threshold UI element be within scope?
I would do it if you give me some pointers as to where I’d have to add it.

The purpose of this command being to create a cleanly recorded manual threshold action?

Where would you want it to live in the menus? Image > Adjust > Manual Threshold…?

1 Like

yes exactly & yes exactly

I think there is an explanation for the design for auto threshold.

Why not simply choose a manual threshold?

“I usually define a manual threshold to extract my objects…, is this ok?” As a recommendation… Whenever possible, try to avoid manual thresholding!!!

2 Likes

Just to clarify again: this thread is not about “Best practices of image thresholding”, which would be indeed a very interesting discussion! Maybe you (and @haesleinhuepf) could open a new thread to discuss this?! I am happy to join there :slight_smile:

But I really feel we are mixing things right now: this thread is just about some technical details about the macro recording of the “Image > Adjust > Threshold” menu item.

@Christian_Tischer How does this look?

If you have any suggestions, please file a PR to improve it.

1 Like