Login  Register

Re: ImageJ2 Java Question: Convolve an image

Posted by Rasband, Wayne (NIH/NIMH) [E] on Apr 19, 2015; 1:27pm
URL: http://imagej.273.s1.nabble.com/ImageJ2-Java-Question-Convolve-an-image-tp5012520p5012521.html

> 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