ImageJ2 Java Question: Convolve an image

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ImageJ2 Java Question: Convolve an image

jumpfunky
Dear list,

I currently have to work with imagej2 and at the moment, the
documentation is rather bad. I have to convolve an image
(Img<FloatType>) with a simple kernel:
1 -2 1
2 -4 2
1 -2 1

How can I do that?

Cheers,
Thorsten

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ2 Java Question: Convolve an image

Rasband, Wayne (NIH/NIMH) [E]
> On Apr 19, 2015, at 5:43 AM, Thorsten Wagner <[hidden email]> wrote:
>
> Dear list,
>
> I currently have to work with imagej2 and at the moment, the
> documentation is rather bad. I have to convolve an image
> (Img<FloatType>) with a simple kernel:
> 1 -2 1
> 2 -4 2
> 1 -2 1
>
> How can I do that?

The imagej-devel maililing list is the best place to ask questions about ImageJ2.

   http://imagej.net/Mailing_Lists

You can do this in ImageJ with a macro using

    run("Convolve...", "text1=[1 -2 1\n2 -4 2\n1 -2 1\n] normalize”);

In JavaScript or a plugin, use

  img = IJ.getImage();
  IJ.run(img, "Convolve...", "text1=[1 -2 1\n2 -4 2\n1 -2 1\n] normalize");

At a lower level, use

  float[] kernel = {1,-2,1,2,-4,2,1,-2,1};
  ImagePlus img = IJ.getImage();
  ImageProcessor ip = img.getProcessor();
  ip.convolve(kernel, 3, 3);
  img.updateAndDraw();

-wayne




--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ2 Java Question: Convolve an image

bnorthan
Hi Thorsten

If you have to work with imagej2 you might also want to consider the
Imagej-ops library.  Imagej-ops is still in beta but it allready has quite
a bit of usefull functionality including convolution.

See 'ConvolveTest.java' 'testConvolve()' function for an example showing
how to convolve Img<FloatType> with imagej-ops

https://github.com/imagej/imagej-ops/blob/master/src/test/java/net/imagej/ops/convolve/ConvolveTest.java

If you do get a chance to look at this code let me know if it is useful as
a means to get started with imagej-ops convolution.  If not I'd like to
rework the example to make it more useful.

Thanks

Brian

On Sun, Apr 19, 2015 at 9:27 AM, Rasband, Wayne (NIH/NIMH) [E] <
[hidden email]> wrote:

> > On Apr 19, 2015, at 5:43 AM, Thorsten Wagner <
> [hidden email]> wrote:
> >
> > Dear list,
> >
> > I currently have to work with imagej2 and at the moment, the
> > documentation is rather bad. I have to convolve an image
> > (Img<FloatType>) with a simple kernel:
> > 1 -2 1
> > 2 -4 2
> > 1 -2 1
> >
> > How can I do that?
>
> The imagej-devel maililing list is the best place to ask questions about
> ImageJ2.
>
>    http://imagej.net/Mailing_Lists
>
> You can do this in ImageJ with a macro using
>
>     run("Convolve...", "text1=[1 -2 1\n2 -4 2\n1 -2 1\n] normalize”);
>
> In JavaScript or a plugin, use
>
>   img = IJ.getImage();
>   IJ.run(img, "Convolve...", "text1=[1 -2 1\n2 -4 2\n1 -2 1\n] normalize");
>
> At a lower level, use
>
>   float[] kernel = {1,-2,1,2,-4,2,1,-2,1};
>   ImagePlus img = IJ.getImage();
>   ImageProcessor ip = img.getProcessor();
>   ip.convolve(kernel, 3, 3);
>   img.updateAndDraw();
>
> -wayne
>
>
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html