Asymetric 3D erosion

Hi,

I would like to erode a mask in 3D asymmetrically. I mean that I would like to erode it more from top to bottom that from bottom to top.
Up to now I have been using the following:

run("CLIJ Macro Extensions", "cl_device=");
		input = getTitle();
		Ext.CLIJ_push(input);
		Ext.CLIJ_minimum3DBox(input,"Eroded",19,19,33);
		Ext.CLIJ_pull("Eroded");
		Ext.CLIJ_clear();

I don’t know if there is a way of doing directly the asymmetric erosion I want but the only way I could think of doing it would be of eroding it twice, and then combining the bottom half of one erosion and the top half of the other. The problem is that I would first need to compute the centre of the object in order to know where to combine it. Also, the results after combining the two halves makes a sort of “step” in the horizontal plane.

Would you have any suggestions on how it is best to do it ?

Thank you very much

Hello LPUoO -

Here is a – perhaps not practical – suggestion:

Speaking in 2-d language, where increasing values of y go down,
you could non-uniformly stretch your image in the vertical direction:

   y --> y^2

carry out your uniform (symmetric) erosion, and then unstretch
your image:

   y --> sqrt (y)

(Of course, by the time you implement your parabolic stretcher /
unstretcher, you probably could have implemented a direct
asymmetric erosion algorithm.)

Thanks, mm

Thank you for the suggestion @mountain_man .
Sadly I have absolutely no idea how to implement this non-uniformly stretching and unstretching.

Would you have a working example ?

Thank you very much

Hello LPUoO -

I don’t have any code that does this. There are various third-party
warping plugins out there, but I didn’t see any that would really do
what you want. (I’m also not aware of any tools that will do
asymmetric erosion.)

Asymmetric erosion (and/or non-uniform stretching) could be
implemented relatively easily with a script or plugin, but doing
so would be something of a programming project.

Thanks, mm

Hey @LPUoO,

that sounds like an interesting project. Unfortunately, I’ve never heard about a project where asymetric erosion was necessary. First of all would you mind sharing an image and tell us a bit more in detail what you would like to do with it? It sounds really interesting.

Furthermore, I see two possible strategies:

  • I’m wondering if an asymmetric erosion is the same as a symmetric erosion plus translation and scaling. CLIJ supports these operations. Example code for the affine transform lives here. Give it a try if you think that makes sense.
  • It would require some time to wrap a mind around the parabolic stretcher you discussed. Basically you need to write the local shift into an image and then use the image as vector field to warp the original image. You find CLIJ example code for image warping here.
    warpedCat Be careful, it’s hypnotising.

Let me know if it works. If you have a cool example script using CLIJ, I would be happy if you would mind sharing it as pull request to the clij-docs repository. The more useful examples, the better.

Cheers,
Robert

1 Like

Hi @haesleinhuepf, thank you for your help. Apologies for the delay in replying.

Below I have an XZ image of a nucleus with tubes inside. I would like to segment the tubes. My plan so far is to threshold the image as in the second pic, create a mask + fill holes then erode it and use that as a mask to exclude the “outer” nuclear envelope. And I do all of this in 3D.

The issue I have is that when thresholding, the apparent thickness is higher in the top and bottom than in the sides. And this is why I thought that and 3D erosion where I erode more in the Z axis than XY would help.

image image

I tried your example code for affine transform but I only get a blank image.

Any way, I’m unsure if warping or affines transformations is the solution.

Thanks for your help

1 Like

Hey @LPUoO,

would you mind sharing the raw data? With that I could play a bit and suggest an alternative workflow…

Cheers,
Robert

1 Like

Hey @haesleinhuepf, Thank you for your help.
Attached is a .rar file with two images. One with some “simple” tubes and the other with some more complex structures. My final aim is to segment these structures in order to be able to count them automatically and to get information about their morphology.

Images for segmentation.rar (16.9 MB)

Thank you very much for your help !

Hey @LPUoO,

I finally detected a misunderstanding. We were discussing about asymetric erosion. However, I guess you are only interested in applying the erosion with different radii in different dimensions, which is referred to as anisotropic erosion. You can just do that with the minimum filter in CLIJ.
image
And I guess you tried, right? Was there any issue with that?

Was there any particular reason why you tried to do it on the GPU? Just from looking at the images, I would say Trainable Weka Segmentation and/or Ilastik might be well suited to segment these membrane-like structures… What other strategies have you tried?

Cheers,
Robert

1 Like

The solution was in front of my eyes all this time and I failed to notice it :pensive:
And yes, I used the minimum filter in CLIJ and somehow the idea that I could change the parameter of the radiusZ totally vanished of my head :man_facepalming:
The reason why I tried to do on the GPU is just that I found that it is much faster than on CPU.

I tried the Weka Segmentation but I found that it was very very time consuming. And as I have about 11,000 images to segment and It took 5 min per image it would have been something like 38 days of processing. (though, maybe I didn’t use it properly). I tried as well linear filters but that only worked with simple tubular structures like in the first image. I haven’t tried Ilastik.

I will try Ilastik now.

Thank you very much for your help!