clij / clijx

Other
4 stars 6 forks source link

Canny Edge Detection #16

Open haesleinhuepf opened 3 years ago

haesleinhuepf commented 3 years ago

Suggested by @pr4deepr

Canny edge detection, just like 3D Edge and Symmetry filter in 3D ImageJ suite (not sure if you already have this?).

See also: https://github.com/clij/assistant/issues/14

pr4deepr commented 3 years ago

Am sure you've seen this, but putting link to the code here from Thomas's 3D ImageJ suite github: Canny edge detection (multithreaded)

Symmetry filter Reference paper for the symmetry filter (I found it quite interesting)

To be honest, the edge detection is fairly quick, so for now it can be incorporating the implementation in 3D ImageJ Suite (not GPU optimised) can be an option..

haesleinhuepf commented 3 years ago

incorporating the implementation in 3D ImageJ Suite (not GPU optimised) can be an option..

Yes, exactly! I already started incorporating 3D ImageJ Suite here: https://github.com/clij/clijx-assistant-imagej3dsuite

How are your Java coding skills btw? 😉

pr4deepr commented 3 years ago

Awesome (not my JAVA coding skills)

Are you planning to include 3D ROI Manager? That would be amazing!

I am familiar with Groovy scripting if that helps, NOT JAVA unfortunately. 😞

haesleinhuepf commented 3 years ago

I am familiar with Groovy scripting if that helps, NOT JAVA unfortunately.

Alright no problem. Let's attempt it like last time: If you can build a groovy script that runs an ImageJ 3D Suite filter, ideally without opening dialogs or windows, I turn it into a CLIJx-assistant plugin for you :-)

Are you planning to include 3D ROI Manager? That would be amazing!

How should that look like? Unfortunately I don't see how the 3D-Manager can be put into a pipeline that re-generates images (that's what the assitant does ;-) ). Which functionalty from the 3D-Manager are you interested in? Btw. you can take a label-map from the assistant and load it into the 3D Manager to postprocess it there...

pr4deepr commented 3 years ago

Alright no problem. Let's attempt it like last time: If you can build a groovy script that runs an ImageJ 3D Suite filter, ideally without opening dialogs or windows, I turn it into a CLIJx-assistant plugin for you :-)

I shall attempt that.

How should that look like? Unfortunately I don't see how the 3D-Manager can be put into a pipeline that re-generates images (that's what the assitant does ;-) ). Which functionalty from the 3D-Manager are you interested in? Btw. you can take a label-map from the assistant and load it into the 3D Manager to postprocess it there...

Good point. I am more interested in a way to manage labelled objects that are being generated. But, this could be done out of assistant as I am currently doing. Otherwise, it will be regenerated everytime as you mentioned.

haesleinhuepf commented 3 years ago

a way to manage labelled objects

What do you mean by manage? That's really interesting! I would love to extend the functionality in the Label > Processing category. Just let me know what's missing 😉

pr4deepr commented 3 years ago

Ohh, ok, so by manager what I mean is being able to interact/query the object parameters and use that to tune/process labels being produced.

As an example, if I have 100 objects in my image stack, I can scroll through the stack, look at the label values of a few "unwanted" objects (because of background or non-specific staining). This is usually after I've used the seeded watershed/ marker controlled watershed to get the entire volume of the object of interest.

Is there anything that distinguishes them from my object of interest? It helps if its microns, because I can translate them to images of different dimensions.

I usually have to write another loop to then exclude objects that fall outside the desired category. This takes a while sometimes. This varies a lot based on the images and celltypes I am interested in, so I cannot give you one parameter that works, sometimes its a combination of them.

With CLIJx assistant, you already have a fair bit of parameters that are generated. If you have an "ROI Manager" like interface which is point and click, where when you click on the name it overlays the selection on the stack (or even across stacks) and another option lists all the parameters, like the one for WEKA features: image

It will be easier for a novice to tune the label processing, and get a complete segmentation pipeline for diverse celltypes..

haesleinhuepf commented 3 years ago

I can scroll through the stack, look at the label values of a few "unwanted" objects (because of background or non-specific staining).

I know that this manual interaction-thingy is kind of cool in the 3D Suite, but it's certainly not a target-functionality of a processing library like clij and workflow-design tool like the assistant. However, I do see an alternative: Can you mark the objects you like to keep and some you want to drop and try label classification? https://clij.github.io/assistant/clijx_weka_label_classifier

With CLIJx assistant, you already have a fair bit of parameters that are generated. If you have an "ROI Manager" like interface which is point and click,

This sounds like something we indeed want in the assistant (fantastic idea! Thanks). I created an issue for that. Let's try to keep issues separated: clij/2/x is for processing/filters; the assistant is a user interface to avoid coding.

pr4deepr commented 3 years ago

I know that this manual interaction-thingy is kind of cool in the 3D Suite, but it's certainly not a target-functionality of a processing library like clij and workflow-design tool like the assistant. However, I do see an alternative: Can you mark the objects you like to keep and some you want to drop and try label classification? https://clij.github.io/assistant/clijx_weka_label_classifier

I will give this a go and see if it works. This may indeed be the way to go.

This sounds like something we indeed want in the assistant (fantastic idea! Thanks). I created an issue for that. Let's try to keep issues separated: clij/2/x is for processing/filters; the assistant is a user interface to avoid coding.

Yup, I start getting a mixed up with all of the clij's Not sure how you keep up!... 😄 Glad you find it useful..

haesleinhuepf commented 3 years ago

Hey @pr4deepr ,

back to Canny Edge Detection. I just uploaded a bunch of new filters to the update site, among them SimpleITKs Canny Edge Detection: image

Would you mind testing it on a typical data set? ITK is also known as a quite fast processing library. Thus, I'd be interested in how you judge performance of that filter in a real scenario.

Thanks!

Cheers, Robert

pr4deepr commented 3 years ago

Hi Robert This is good! The itk page is a great collection of filters and operations!!

I tried it out just now. Original, Second image is using the 3D edge and symmetry filter. Third image is the canny edge with default parameters image

I applied a gaussian on the first image and it became much better, but I am getting this big outline outside all the cells.It encircles the structure: image Would like to optimise this to get nice clean edges. Its working pretty well, just a bit more post-processing I reckon.

I tried it on some other images: Original image, binary and three diff values of variance. image

When I apply a median filter of 2,2,2 to the Canny edge filter with default values, I get this: image

Comparison with the 3D Edge and Symmetry filter: image

Pradeep

haesleinhuepf commented 3 years ago

Hey @pr4deepr ,

huh, that's many screenshots :-)

I was hoping that you can tell me what good parameters for this filter are and how it's different from what you're used to. I would ike to point these things out in the documentation, so that others can "just" use it ;-)

Thanks for your support!

Cheers, Robert

pr4deepr commented 3 years ago

Hi Robert From the documentation, variance and max error control the smoothing of the edge.

Generally, increasing the value of the variance will give a smoother edge. Maximum error appears to control for this smoothing and how much it resembles original image. Essentially, using large maximum error values with large variance values is recommended.

Example, Low variance, low error image

High variance, low error (smoothing gets rid of jagged edges at the bottom, and also small particles/edges): image

High variance, High error (some of the jaggedness of the edges and structure of original edge is retained): image

I am not sure about the threshold values though... Documentation on ITK website says lower threshold is the lowest threshold allowed, but the threshold values I enter here do not seem to correspond to the lowest thresholds or highest thresholds in the image.

For ex, the threshold is 7000 on this image, but if I enter 7000 or whatever value on lower threshold, it does not really affect the edge output image

But, if I enter 300 in upper threshold, it gets rid of the lower thresholds. Anything higher than 1000 or so and it all disappears: image If I switch the values around, there are no edges as well..

I don't think I understand this section well enough...

Cheers Pradeep

pr4deepr commented 3 years ago

For the above image, as the structure is relatively thick/big, a variance of 8 and max error of 0.3-0.6 worked quite well. I will have a look at smaller cells or other structures and post what I find here

pr4deepr commented 3 years ago

In regard to the threshold values, I did a quick search and came across a lot of documentation on the use of lower and upper threshold. Dunno how I missed that..

Essentially,

This suggestion worked for me when segmenting some nuclei: Get Otsu threshold value Upper threshold=Otsu threshold Low threshold=0.5∗upperthresh

I applied this ostu method on this example: image

Sources:

  1. https://au.mathworks.com/matlabcentral/answers/552703-canny-edge-detection-threshold-values-meaning
  2. http://www.kerrywong.com/2009/05/07/canny-edge-detection-auto-thresholding/
  3. https://www.quora.com/How-do-I-set-the-upper-and-lower-threshold-in-canny-edge-detection