Help with color threshold

Hi

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

selectWindow(“2_D_pre_clear.tif”);
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:

image

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
java.util.concurrent.FutureTask.report(FutureTask.java:122)
java.util.concurrent.FutureTask.get(FutureTask.java:192)
trainableSegmentation.FeatureStack.updateFeaturesMT(FeatureStack.java:3047)
trainableSegmentation.FeatureStack.updateFeaturesMT(FeatureStack.java:2780)
trainableSegmentation.FeatureStackArray.updateFeaturesMT(FeatureStackArray.java:190)
trainableSegmentation.WekaSegmentation.trainClassifier(WekaSegmentation.java:5271)
trainableSegmentation.Weka_Segmentation$4.run(Weka_Segmentation.java:1496)

at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at trainableSegmentation.FeatureStack.updateFeaturesMT(FeatureStack.java:3047)
at trainableSegmentation.FeatureStack.updateFeaturesMT(FeatureStack.java:2780)
at trainableSegmentation.FeatureStackArray.updateFeaturesMT(FeatureStackArray.java:190)
at trainableSegmentation.WekaSegmentation.trainClassifier(WekaSegmentation.java:5271)
at trainableSegmentation.Weka_Segmentation$4.run(Weka_Segmentation.java:1496)

Caused by: java.lang.OutOfMemoryError: Java heap space
at ij.process.FloatProcessor.(FloatProcessor.java:38)
at trainableSegmentation.FeatureStack.calculateHessianOnChannel(FeatureStack.java:979)
at trainableSegmentation.FeatureStack.calculateHessian(FeatureStack.java:943)
at trainableSegmentation.FeatureStack.access$2(FeatureStack.java:938)
at trainableSegmentation.FeatureStack$10.call(FeatureStack.java:932)
at trainableSegmentation.FeatureStack$10.call(FeatureStack.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

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