Help with color threshold


Im using Fiji for the first time. I need to analyse images I made for my master thesis.
The goal is to calculate the percentage ‘blue smear’ on the pictures.

I’m color thresholding with the Shanbhag method (I have no idea why, people told me so). Most of the time this is quite accurate but sometimes it’s not possible to threshold all the blue without selecting something that’s not part of the smear. Most of the time its the ‘lighter blue’ that’s not possible to select.
I really have no idea what i’m doing wrong or how if there is a different way to do this so I would be really glad if somebody could help me with this.

I think the solution is quite simple but I can’t seem to find it, I already tried to google/youtube tutorials but it doesn’t help me. The program is to advanced for me…

So in the first picture is before thresholding, 2nd is after I colored my threshold grey. I just can’t select/color the ‘lightblue-grey’ smear in the middle without selecting other part

Could you maybe macro record the steps you are currently doing?

…and copy and paste the recorded text here?

I just tried to reproduce your workflow by applying the [ Image > Adjust > Autothreshold ] Shanbhag method to a color (RGB) image and got a message that RGB images are in fact not allowed, but only 8-bit and 16-bit…

1 Like

run(“Color Threshold…”);
setForegroundColor(127, 127, 127);
run(“Fill”, “slice”);

I just ‘play’ with the Hue, Saturation and Brightness in the Color Threshold window but I really have no idea what i’m doing. Im just trying to color as much ‘blue’ as possible…

EDIT: Like I said, in some pictures I can color everything but sometimes it seems impossible to select all the blue without selecting parts that aren’t stained with the blue smear…

1 Like

I see now. Thank you very much.
It will probably not improve the selection, but it will hopefully somewhat help to you to better understand what you are doing :wink:
I ran [Image > Color > Split Channels], which gives you three images with the respective red, green, and blue components of your image. Next, on the blue channel I tried a simple manual threshold [Image > Adjust > Threshold...]:

If that’s not sufficient to get the job done, I feel might need some machine learning approach, like the Trainable Weka Segmentation. Maybe @iarganda could help here?

1 Like

Thank you for your reply. I will try to split the channels. Maybe thats better :slight_smile:.
I tried the Trainable Weka Segmentation but it crashed 3 times so maybe I’m doing something wrong or my PC can’t handle it :confused:

Hello @pboder and welcome to the ImageJ forum!

In the Color Threshold plugin, try selecting the Lab color space. Maybe there you can isolate the blue color in a simpler way:


Did you get any error message?

1 Like

This is the message from the ‘log’ screen.
Warning: ImageScience library unavailable. Some training features will be disabled.
Warning: ImageScience library unavailable. Some training features will be disabled.
Creating feature stack…
Updating features of slice number 1…
Error when updating feature stack.
Feature stack was not updated.
The traning did not finish.

This is the error from the ‘console’ screen.

WARNING: core mtj jar files are not available as resources to this classloader (sun.misc.Launcher$AppClassLoader@c387f44)
java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space

at java.util.concurrent.FutureTask.get(
at trainableSegmentation.FeatureStack.updateFeaturesMT(
at trainableSegmentation.FeatureStack.updateFeaturesMT(
at trainableSegmentation.FeatureStackArray.updateFeaturesMT(
at trainableSegmentation.WekaSegmentation.trainClassifier(
at trainableSegmentation.Weka_Segmentation$

Caused by: java.lang.OutOfMemoryError: Java heap space
at ij.process.FloatProcessor.(
at trainableSegmentation.FeatureStack.calculateHessianOnChannel(
at trainableSegmentation.FeatureStack.calculateHessian(
at trainableSegmentation.FeatureStack.access$2(
at trainableSegmentation.FeatureStack$
at trainableSegmentation.FeatureStack$
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$

If it’s an easy solution I would be glad to hear. But if it’s to much work for you to figure out what’s wrong I can use the settings with ‘Lab’ as color space, that’s giving better results then the HSB filter :slight_smile:

Thank you very much for your help!

You are getting and out of memory error. Probably your images are too large or you are using too many feature for the RAM you have on your machine.

1 Like