How to do a Binary image for a specific color

Tags: #<Tag:0x00007fb87e0ec958> #<Tag:0x00007fb87e0ec7c8> #<Tag:0x00007fb87e0ec570>



I need to do a binary image for the color red and anther one for the color green. How do I say to ImageJ which color he should select ?


Considering this looks like a result of another software running a segmentation, I would recommend checking on that software if you can export the channels as a gray level image, which makes thresholding and selecting the values much more simple.

Did you use Ilastik by any chance?


For this segmentation i used Fiji


When opening a new topic that is a continuation of a previous discussion, please link it, so others can follow.

I assume you used the Trainable Weka Segmentation plugin in Fiji to get this? (It helps to provide all the information, so others don’t waste time suggesting you things that won’t help you.)

The result you get from this plugin is actually not an RGB image, but an indexed 8-bit color image. That means each class (color) has a pixel index value between 0 and 255.

You can get a binary mask for each class by simple thresholding, e.g. with these lines of macro code:

setThreshold(1, 1);
setOption("BlackBackground", true);
run("Convert to Mask");

Just change the setThreshold command to the index you’d like to have.



thank you so much for your answer.

Actually i need to do the binary image of this two different colors in order to achieve to calculate the surface of contact between the green and the red (biomaterial and bone)

Can you please check this discussion?


I did check that discussion, that’s why I linked to it in my post above :slight_smile:

Did you try my suggestion? It should give you exactly what you need. If you need to do this for multiple colors/classes, just duplicate your image before making it binary.


With your code i got this image:

But the problem is that i just need the surface of contact between the red and green. So i need something like this: