Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DeconWithGrid.groovy #37

Merged
merged 2 commits into from
Feb 15, 2024
Merged

Update DeconWithGrid.groovy #37

merged 2 commits into from
Feb 15, 2024

Conversation

andmccall
Copy link
Contributor

Was looking at the groovy example scripts and noticed this one didn't work. Looks like RichardsonLucyF changed to RicahdrsonLucyC at some point

Was looking at the groovy example scripts and noticed this one didn't work. Looks like RichardsonLucyF changed to RicahdrsonLucyC at some point
@bnorthan
Copy link
Contributor

bnorthan commented Feb 14, 2024

Hi @andmccall

Thanks for taking a look at this. This is a really important example meant to show the importance of edge handling and deconvolution acceleration and it sucks that it didn't work for a while.

The original version was definitely broke, but I couldn't get your version to work for me either (on a fresh install of Fiji). Below is what finally worked. (I also took out the small_kernel, as that didn't really contribute to the example)

#@ OpService ops
#@ UIService ui
#@ ConvertService convert
#@ DatasetService data

import net.imglib2.type.numeric.real.FloatType;
import net.imagej.ops.Op
import net.imglib2.outofbounds.OutOfBoundsConstantValueFactory
import net.imagej.ops.deconvolve.RichardsonLucyC
import net.imglib2.util.Util

// create the sample image
base = ops.run("create.img", [150, 100], new FloatType())
formula = "p[0]^2 * p[1]"
ops.image().equation(base, formula)

ui.show("input image", base);

// create kernel
kernel_big = ops.run("create.img", [20,20], new  FloatType())

ops.image().equation(kernel_big, "p[0]")

// convolve with large kernel
convolved_big = ops.filter().convolve(base, kernel_big)

ui.show("convolved", convolved_big);

// deconvolve with Richardson Lucy
base_deconvolved_big=ops.create().img(convolved_big, new FloatType())
base_deconvolved_big = ops.deconvolve().richardsonLucy(base_deconvolved_big, convolved_big, kernel_big, null, new OutOfBoundsConstantValueFactory<>(Util.getTypeFromInterval(kernel_big).createVariable()), 10)

// deconvolve with non-circulant Richardson Lucy
base_deconvolved_big_noncirc=ops.create().img(convolved_big, new FloatType())
base_deconvolved_big_noncirc = ops.deconvolve().richardsonLucy(base_deconvolved_big_noncirc, convolved_big, kernel_big, null, null, null, null, null, 50, true, false)

// deconvolve with accelerated non-circulalant Richardson LUcy
base_deconvolved_big_acc_noncirc=ops.create().img(convolved_big, new FloatType())
base_deconvolved_big_acc_noncirc = ops.deconvolve().richardsonLucy(base_deconvolved_big_acc_noncirc, convolved_big, kernel_big, null, null, null, null, null, 50, true, true)

ui.show("RL",base_deconvolved_big)
ui.show("RLNon-Circ",base_deconvolved_big_noncirc)
ui.show("RL Acc/Non-Circ",base_deconvolved_big_acc_noncirc)

Below is the result you should get, which shows in this extreme example (with structure right to the edge and a big PSF) you need non-circulant edge handling to get an acceptable result and the acceleration give an even sharper result. Can you replicate this either using my code or you RichardsonLucyC version? If the latter we should discuss further why the RichardsonLucyC version is working for you but not me.

image

@andmccall
Copy link
Contributor Author

Hi @bnorthan,

I double checked and hadn't even noticed the error that popped up on my version, just saw the original image, convolved image and what looked like a decent deconvolved image and thought that was the whole output.

I tried your version and it works great.

Brian's much improved version. I also went through and removed some of the now unnecessary parameters and libraries
@bnorthan bnorthan merged commit 362a325 into imagej:master Feb 15, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants