Creating and Adjusting binary mask

Hey all,

So I am trying to create a binary mask for a stack - that i’l eventually convert to a mesh. However I’m having some issue getting the binary mask to accurately resemble the original images.

The main problem is that at the outer edge the threshold seems to ‘smooth over’ the outer columns of the image (as can be seen in the second image), where as the threshold needs to be more like the one in the third image (but as you can see adjusting the threshold deselects the bulk of the image).

So I just wonder if there is a way to overcome this, I have tried using the erosion and dilation tools, post thresholding however have had little success.

Is it possible to create separate binary masks for different parts of the images or something similar?

Thanks!

@jake

Would you be able to attach an original image here for us to see? It’s always most helpful to have access to the raw dataset…

But simply thresholding your image won’t be enough - as you can see from this snapshot you posted - you have variation in the intensity of your ‘object’ - brighter pixels being on the periphery… which is why simple thresholding is proving difficult.

Perhaps there are some pre-processing steps that will help in this… you can also look into a few other plugins for segmentation help:

But providing the original image is the best first step… then we can test things out and give you a better idea of what you can try specifically.

eta :slight_smile:

1 Like

Thanks, I will give them a go!

I’ve attached one of the original images (it’s meant to be an image sequence but apparently I can’t upload other attachements :frowning: ).

edit: the image sequence can be viewed here https://www.dropbox.com/s/rvztz53dlzc9v96/quarter.zip?dl=0

No worries @jake

So just working with a single image in your stack… I got the following results with TWS:

Using these settings:

This could definitely be improved… and also - I didn’t do any pre-processing - which might help too. But at least you get an idea of what segmentation with TWS could look like. :slight_smile:

eta

1 Like

Good day Jake,

here is a little ImageJ-macro that may help:

run("Subtract Background...", "rolling=50 light sliding");
setAutoThreshold("Triangle dark");
setOption("BlackBackground", false);
run("Convert to Mask");
run("Invert LUT");
run("Invert");

Paste the above macro code to an empty macro window (Plugins >> New >> Macro) and run it.

Here is the result for your sample image “Sphaerechinus0000”:

HTH

Herbie

1 Like

Awesome guys, a lot better than where I was getting with it - i’l keep adjusting anyway :slight_smile:

1 Like

Jake,

it would be interesting to know what appears sub-optimum.
(The point-like defects can be reduced by median-filtering (r = 1) the result.)

Just in case: Don’t try with hand-set thresholds.

Regards

Herbie

@anon96376101 I was wondering if you could explain a little about that macro, so I may adjust it a little?

As it works great for the first image in the stack, however if I apply it to all 400 images, the rest are processed pretty much completely white.

Thanks

Good day Jake!

[…] the rest are processed pretty much completely white.

Not here, for me everything works as expected.

requires("1.51w");
run("Subtract Background...", "rolling=50 light sliding");
setAutoThreshold("Triangle dark");
setOption("BlackBackground", false);
run("Convert to Mask");
run("Invert LUT");
run("Invert");
run("Median...", "radius=1");
exit();

Concerning the macro, you are to study the macro coding docs:
https://imagej.nih.gov/ij/developer/macro/macros.html
https://imagej.nih.gov/ij/developer/macro/functions.html

Of course, if you have specific questions please go ahead!

Regards

Herbie

So I think the problem was that the auto-threshold was only applying to the first image for some reason.

I adjusted the macro to the following:

run(“Subtract Background…”, “rolling=50 light sliding stack”);
run(“Auto Threshold”, “method=Triangle dark stack”);
setOption(“BlackBackground”, false);
run(“Convert to Mask”);
run(“Invert LUT”);
run(“Invert”);
run(“Median…”, “radius=1”);
exit();

and it seems to be working now.

The only problem now is that i’m losing some of the detail in the top left corner of the image - but I will have a play around and see if it can be improved.

1 Like

Jake,

you’re the expert concerning the biological meaning but I can’t see any problems with the upper left corner:

In any case, thresholds are a tricky affair and a thresholded image is always a kind of compromise …

Regards

Herbie

The upper left corner is in fact mainly hollow (darker), however this is not the case in the threshold stack. But yes I agree there is definitely an art to it :slight_smile:

Jake,

you may be right but the image tells us that there is a pronounced modulation in this area and I doubt that there is a generally valid method to make it disappear.

Regards

Herbie

Hi @jake
I just found your post and was wondering if you could tell me a little bit more about the process you followed for creating the mesh out of the binary mask you created. I am trying to do something similar and haven’t found a way to do it.
Thanks in advance,
Juliana

Hi @JuliSanchezP
So I tried using different thresholding/filtering techniques but had too severe a problem with non-uniform illumination, which was more a problem with the raw image data than the analysis. In the end, I just segmented the above image into smaller sub-volumes in order to minimise the non-uniform illumination effects and just used a standard threshold.

This paper may be of interest

A comprehensive and user‐friendly framework for 3D‐data visualisation in invertebrates and other organisms

https://onlinelibrary.wiley.com/doi/full/10.1002/jmor.20938