Thresholding with a fixed value - could this be more difficult?

Hi,
I recently wanted to do the simplest thing: threshold some images with the same fixed value.
None of the options in Image-Adjust-Threshold seemed to use my fixed value.
Using Image-Threshold-Apply Threshold results in an error: "A ComputeThreshold is required but none exists."
The only way I found was to use Image-Adust-Brightness/Contrast, Set min and max to 100 and 101 (say), and apply LUT.

There must/should be an easier way.
What am I doing wrong?
Cheers.
I am using the latest version of Fiji.

1 Like

Could you be more specific and describe the workflow you use?

A bunch of images could be easily thresholded automatically with a recorded macro command, e.g.:

in:

Plugins->New->Macro

Execute the following command to set a threshold (adjust the values for min, max):

setThreshold(126, 255);

Use the macro recorder to add some custom commands:

https://imagej.nih.gov/ij/docs/guide/146-31.html#sub:Record

And apply it to a bunch of images:

It is true that when you record the “Set” and then “Apply” buttons on the Thresholder, it looks strange

Example: Open one image, set threshold manually and hit “Apply”.

setThreshold(2, 255);
//setThreshold(2, 255);
setOption("BlackBackground", false);
run("Convert to Mask", "method=Default background=Dark");

The Convert to Mask option only takes auto thresholds, is that correct?

@paulbarber you could use something like so:

setThreshold(2, 255);
run("Create Mask");

Then you are sure that it is creating a Mask from the threshold value you set, like @Bio7 was saying.
Note that Create Mask makes a new image.

1 Like

Thanks for your replies.
OK. Part of my issue was to do with the fact that I was using a stack. If I have an image on its own then Image-Adjust-Threshold menu option, Set then Apply works as I would expect and applies my manual threshold. With a stack, an extra “Convert Stack to Binary” window appears that overrides the manual threshold.

With that issue out the way. The macros that you both suggest work for me.
I can use
run(“Stack to Images”);
beforehand and it’s all fine.

So, I think my issues was due to a difference in the way stacks are dealt with.
Cheers,

I bumped into this thread as I was experiencing a similar issue with the additional “Convert Stack to Binary” window not applying my manual threshold. After asking around, a team member kindly pointed out that you need to untick the “Calculate threshold for each image” option on that window and then Fiji (running ImageJ 1.52p) will process the entire stack with the threshold you’ve set. So, no need to convert a stack to images, then Apply the threshold, and then convert back to a stack if that’s the final format you want your images in, for example.

In a macro it’d look like this:
setThreshold(x, y)
run("Convert to Mask", "method=Default background=Dark black");
where the calculate option is omitted from the 2nd line.

Just sharing in case anyone encounters this issue.

2 Likes