Performing convolution using ImageJ2

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Performing convolution using ImageJ2

Thorsten Wagner
Dear list,

I try to perform a simple convolution using imagej2. Unfortunately, it
failed!

This is my code:
http://pastebin.com/CqBgcLXd

This is the exception:
http://pastebin.com/KHkeGGAJ

I would be grateful for any help.

Regards,
Thorsten

_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel
Reply | Threaded
Open this post in threaded view
|

Re: Performing convolution using ImageJ2

Curtis Rueden
Hi Thorsten,

> I try to perform a simple convolution using imagej2. Unfortunately, it
> failed!

The exception you receive is because you are creating a new ImageJ application context, rather than reusing the existing one. This happens because you write:

   final ImageJ ij = new ImageJ();

The handle to the existing context can be obtained in one of two ways:

1) If you are writing an ImageJ1 plugin (e.g., an ij.plugin.Plugin), then you can write:

    // retrieve the ImageJ application context
    final Context context = (Context) IJ.runPlugIn("org.scijava.Context", "");
    final ImageJ ij = new ImageJ(context);

2) If you are writing an ImageJ2 plugin, then you can write:

    @Parameter
    private OpService ops

And just call "ops.convolve(...)" in your code.

Or if you really want the "ImageJ" object, you can write:

    @Parameter
    private ImageJ ij;

See also:

Regards,
Curtis

On Mon, Apr 20, 2015 at 4:53 AM, Thorsten Wagner <[hidden email]> wrote:
Dear list,

I try to perform a simple convolution using imagej2. Unfortunately, it
failed!

This is my code:
http://pastebin.com/CqBgcLXd

This is the exception:
http://pastebin.com/KHkeGGAJ

I would be grateful for any help.

Regards,
Thorsten

_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel


_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel
Reply | Threaded
Open this post in threaded view
|

Re: Performing convolution using ImageJ2

Brian Northan
Hi Thorsten

I'm working on a convolution tutorial for imagej-tutorials.  (Though it looks like you are almost there anyway)

https://github.com/imagej/imagej-tutorials/blob/convolution/using-ops/src/main/java/ConvolutionOps.java

A couple of things to note for small kernels

1.  For small kernels there is no practical need to use "borderSize".  Under the hood the default border size is set to kernelSize/2.  The border size can be used if the kernel is very large.  In that case you could force it to use a smaller border size to improve speed (the trade off would be the possibility of edge artifacts).

2.  The fast convolution for small symmetric kernels has not been implemented in ops yet (it is a matter of wrapping code from imglib2).  However long term it will be, and that will make ops very powerful.   A high level programmer will not have to worry about that detail.  Under the hood ops will choose the correct type of convolution based on the kernel. 

Brian

On Mon, Apr 20, 2015 at 4:25 PM, Curtis Rueden <[hidden email]> wrote:
Hi Thorsten,

> I try to perform a simple convolution using imagej2. Unfortunately, it
> failed!

The exception you receive is because you are creating a new ImageJ application context, rather than reusing the existing one. This happens because you write:

   final ImageJ ij = new ImageJ();

The handle to the existing context can be obtained in one of two ways:

1) If you are writing an ImageJ1 plugin (e.g., an ij.plugin.Plugin), then you can write:

    // retrieve the ImageJ application context
    final Context context = (Context) IJ.runPlugIn("org.scijava.Context", "");
    final ImageJ ij = new ImageJ(context);

2) If you are writing an ImageJ2 plugin, then you can write:

    @Parameter
    private OpService ops

And just call "ops.convolve(...)" in your code.

Or if you really want the "ImageJ" object, you can write:

    @Parameter
    private ImageJ ij;

See also:

Regards,
Curtis

On Mon, Apr 20, 2015 at 4:53 AM, Thorsten Wagner <[hidden email]> wrote:
Dear list,

I try to perform a simple convolution using imagej2. Unfortunately, it
failed!

This is my code:
http://pastebin.com/CqBgcLXd

This is the exception:
http://pastebin.com/KHkeGGAJ

I would be grateful for any help.

Regards,
Thorsten

_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel


_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel



_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel
Reply | Threaded
Open this post in threaded view
|

Re: Performing convolution using ImageJ2

Thorsten Wagner
Dear Brian,

thank you for the link! I'm approaching to a solution. However, I followed your tutorial but I stell get a exception:

That's my code:

What I'm doing wrong?

Cheers,
Thorsten



On Mon, Apr 20, 2015 at 4:25 PM, Curtis Rueden <[hidden email]> wrote:
Hi Thorsten,

> I try to perform a simple convolution using imagej2. Unfortunately, it
> failed!

The exception you receive is because you are creating a new ImageJ application context, rather than reusing the existing one. This happens because you write:

   final ImageJ ij = new ImageJ();

The handle to the existing context can be obtained in one of two ways:

1) If you are writing an ImageJ1 plugin (e.g., an ij.plugin.Plugin), then you can write:

    // retrieve the ImageJ application context
    final Context context = (Context) IJ.runPlugIn("org.scijava.Context", "");
    final ImageJ ij = new ImageJ(context);

2) If you are writing an ImageJ2 plugin, then you can write:

    @Parameter
    private OpService ops

And just call "ops.convolve(...)" in your code.

Or if you really want the "ImageJ" object, you can write:

    @Parameter
    private ImageJ ij;

See also:

Regards,
Curtis

On Mon, Apr 20, 2015 at 4:53 AM, Thorsten Wagner <[hidden email]> wrote:
Dear list,

I try to perform a simple convolution using imagej2. Unfortunately, it
failed!

This is my code:
http://pastebin.com/CqBgcLXd

This is the exception:
http://pastebin.com/KHkeGGAJ

I would be grateful for any help.

Regards,
Thorsten

_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel



_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel



_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel
Reply | Threaded
Open this post in threaded view
|

Re: Performing convolution using ImageJ2

Brian Northan
Hi Thorsten

Your code looks fine.  It is a problem in my convolution ops code.

I updated the convolution branch in tutorials to work with your use-case. 
The problem was that the ops framework did not correctly choose 'NaiveConvolution' (direct convolution with small kernel).  Then even when I forced it to (by referring to NaiveConvolution.class directly) it did not extend the images properly (see https://github.com/imagej/imagej-ops/issues/98)

If you get a chance let me know if this new example works.  The example is now too complicated, but if it works for you I can spend some time this week integrating this logic into the op (so you can write nice concise code).

Brian

On Tue, Apr 21, 2015 at 9:35 AM, Thorsten Wagner <[hidden email]> wrote:
Dear Brian,

thank you for the link! I'm approaching to a solution. However, I followed your tutorial but I stell get a exception:

That's my code:

What I'm doing wrong?

Cheers,
Thorsten



On Mon, Apr 20, 2015 at 4:25 PM, Curtis Rueden <[hidden email]> wrote:
Hi Thorsten,

> I try to perform a simple convolution using imagej2. Unfortunately, it
> failed!

The exception you receive is because you are creating a new ImageJ application context, rather than reusing the existing one. This happens because you write:

   final ImageJ ij = new ImageJ();

The handle to the existing context can be obtained in one of two ways:

1) If you are writing an ImageJ1 plugin (e.g., an ij.plugin.Plugin), then you can write:

    // retrieve the ImageJ application context
    final Context context = (Context) IJ.runPlugIn("org.scijava.Context", "");
    final ImageJ ij = new ImageJ(context);

2) If you are writing an ImageJ2 plugin, then you can write:

    @Parameter
    private OpService ops

And just call "ops.convolve(...)" in your code.

Or if you really want the "ImageJ" object, you can write:

    @Parameter
    private ImageJ ij;

See also:

Regards,
Curtis

On Mon, Apr 20, 2015 at 4:53 AM, Thorsten Wagner <[hidden email]> wrote:
Dear list,

I try to perform a simple convolution using imagej2. Unfortunately, it
failed!

This is my code:
http://pastebin.com/CqBgcLXd

This is the exception:
http://pastebin.com/KHkeGGAJ

I would be grateful for any help.

Regards,
Thorsten

_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel



_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel




_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel
Reply | Threaded
Open this post in threaded view
|

Re: Performing convolution using ImageJ2

Thorsten Wagner
Dear Brian,

thank you for your efforts! Your example works perfectly! 

Thank you very much.

Cheers,
Thorsten

Am Dienstag, den 21.04.2015, 11:56 -0400 schrieb Brian Northan:
Hi Thorsten

Your code looks fine.  It is a problem in my convolution ops code.

I updated the convolution branch in tutorials to work with your use-case. 
The problem was that the ops framework did not correctly choose 'NaiveConvolution' (direct convolution with small kernel).  Then even when I forced it to (by referring to NaiveConvolution.class directly) it did not extend the images properly (see https://github.com/imagej/imagej-ops/issues/98)

If you get a chance let me know if this new example works.  The example is now too complicated, but if it works for you I can spend some time this week integrating this logic into the op (so you can write nice concise code).

Brian

On Tue, Apr 21, 2015 at 9:35 AM, Thorsten Wagner <[hidden email]> wrote:
Dear Brian,

thank you for the link! I'm approaching to a solution. However, I followed your tutorial but I stell get a exception:

That's my code:

What I'm doing wrong?

Cheers,
Thorsten



On Mon, Apr 20, 2015 at 4:25 PM, Curtis Rueden <[hidden email]> wrote:
Hi Thorsten,

> I try to perform a simple convolution using imagej2. Unfortunately, it
> failed!

The exception you receive is because you are creating a new ImageJ application context, rather than reusing the existing one. This happens because you write:

   final ImageJ ij = new ImageJ();

The handle to the existing context can be obtained in one of two ways:

1) If you are writing an ImageJ1 plugin (e.g., an ij.plugin.Plugin), then you can write:

    // retrieve the ImageJ application context
    final Context context = (Context) IJ.runPlugIn("org.scijava.Context", "");
    final ImageJ ij = new ImageJ(context);

2) If you are writing an ImageJ2 plugin, then you can write:

    @Parameter
    private OpService ops

And just call "ops.convolve(...)" in your code.

Or if you really want the "ImageJ" object, you can write:

    @Parameter
    private ImageJ ij;

See also:

Regards,
Curtis

On Mon, Apr 20, 2015 at 4:53 AM, Thorsten Wagner <[hidden email]> wrote:
Dear list,

I try to perform a simple convolution using imagej2. Unfortunately, it
failed!

This is my code:
http://pastebin.com/CqBgcLXd

This is the exception:
http://pastebin.com/KHkeGGAJ

I would be grateful for any help.

Regards,
Thorsten

_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel



_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel





_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel