Colour threshold macro, I don't want the stacks :/




I want to use the macro function on colour threshold. But when I use the macro, I get a stack of HSB or RBG as a result, and not the result that I get by manually using the Threshold Colour. Is there any way to avoid this, or to merge the stack into the combined picture?

Any quick help would be greatly appreciated!




Would you be able to share one of the images you are using - as well as a minimal macro code example that we can run to try to recreate the issue you are seeing? This is the best way for us to help you…

eta :slight_smile:

Too - to look up built-in functionality for stacks, check out the Stacks section of the ImageJ User Guide



Thank you for your response! I was very busy doing field work the past 1,5 week, therefore my late reponse.
First of all I set “set measurements” to only “mean gray value”
Then i open the (16.6 KB) with the ROI manager. I go to “more” > “multi measure” > and check “Append results”
After that set the colour threshold to the desired boundaries with RGB and B&W, and check “dark backgroud” Look at the first image now, it has the plants perfectly thresholded.
Following I open the macro recorder, and click macro in the color threshold window.
I open process>batch>macro and paste the code of the treshold in the text box. Below that code I add “roiManager(“multi-measure measure_all one append”);” to analyse my ROI’s for mean grey value per picture.
So when I process the batch, or when I test the macro I suddenly get picture nr 2! The macro made my image into a RGB stack, and not in the original thresholded image… Yes, I can see it does that in the code, but I just want the desired threshold to return.

Here are is the macro, folowed by the images. I added 4 extra so you can test a batch analysis like I do. Your help is greatly appreciated!


// Color Thresholder 2.0.0-rc-65/1.52b
// Autogenerated macro, single images only!
run("RGB Stack");
run("Convert Stack to Images");
for (i=0;i<3;i++){
  setThreshold(min[i], max[i]);
  run("Convert to Mask");
  if (filter[i]=="stop")  run("Invert");
imageCalculator("AND create", "0","1");
imageCalculator("AND create", "Result of 0","2");
for (i=0;i<3;i++){
selectWindow("Result of 0");
selectWindow("Result of Result of 0");
// Colour Thresholding-------------

roiManager("multi-measure measure_all one append");

Nr. 1

Nr. 2

Test images:



Sorry - can we just take a quick step back before moving forward… what exactly is your goal in this analysis workflow? You want to segment the plants? To measure what? Do you need each ‘pot’ region segmented as well? How exactly do you want your output data saved? I don’t quite understand the problem there that you are currently having… you want a binary image after color thresholding - yes? - to then analyze further?




Hi Etarena,

I want to determine the amount of green pixels or Leaf Area in each well of the tray.
So yes each pot/well region has to be segmented.
I want my output data to be saved as a table with the wells from 1 to 104 horizontally and the traynumbers on the vertical row. The data will consist of the mean grey value. This mean grey value i can calculate to surfave, since 0 = 0% black and 255 is 100% black. Black in the binary image stands for green, as determined by the color threshold.

When I use the color thresholder on itself I get a very nice threshold, see image Nr. 1. But when I use the macro, I get image Nr. 2 (I see now that these are two different images originally, but the point is that the threshold is not correct). As you can see in the top left corner in image Nr. 2 this is a RGB stack.
My main question is this: When I use the color threshold macro, I want the same resulting image as when I use the color threshold manually.

I hope things are clear now.

Thanks for your interest and response



You can check out these older forum posts for things to try:




Hello Etarena,Thanks for your reply, I have read both posts, but i cannot find the answer, and I searched the forums too before i asked the question.

My question is actually quite simple. Is there a way to just get the same image as when I manually use the color thresholder?