2

I want to use find edges option of the ImageJ, have the edges-found array and save it to another file programatically.

ImagePlus ip1 = IJ.openImage("myimage.jpg");
ImageProcessor ip = new ColorProcessor(ip1.getWidth(), ip1.getHeight());
ip.findEdges();

However, the function findEdges is abstract and I can't have the edge-found image.

EDIT:

I wrote the following lines:

ip.findEdges();
BufferedImage bimg = ip.getBufferedImage();

However, when I try to print out the RGB values of the BufferedImage, it only prints "-16777216" for each pixel RGB.

İsmet Alkan
  • 5,361
  • 3
  • 41
  • 64

2 Answers2

2

OK, I got the solution, the problem was that I didn't connect the ColorProcessor with the image.

ColorProcessor ip = new ColorProcessor(ImageIO.read(new File("my_image.jpg")));
ip.findEdges();
BufferedImage bimg = ip.getBufferedImage();
İsmet Alkan
  • 5,361
  • 3
  • 41
  • 64
  • If you do this, you can declare `ip` as `ImageProcessor` like you did in your question – Attila May 18 '12 at 12:54
  • The left hand side of the initialization don't matter here, as it's just a reference to a memory block. Right hand side is the actual class the operations will be looked up first, so what you say is right. – İsmet Alkan May 18 '12 at 13:00
0

ImageProcessor is an abstract class, that lets the derived classes provide the appropriate implementation. You need to declare ip as type ColorProcessor:

ColorProcessor ip = new ColorProcessor(ip1.getWidth(), ip1.getHeight()); 
ip.findEdges();
Attila
  • 28,265
  • 3
  • 46
  • 55
  • How can I reach the edge-found array? I also initialize it with ColorProcessor, it will look at ColorProcessor's functions in vtable first, I guess. – İsmet Alkan May 18 '12 at 12:34
  • I am no ImageJ expert, but looking at the [documentation](http://rsbweb.nih.gov/ij/developer/api/ij/process/ColorProcessor.html) it seems there is no way to do that. Rather `findEdges()` applies a transformation to the image, so that when you get the image (e.g. via `createImage()`), you will see the edges detected, instead of the original image. – Attila May 18 '12 at 12:41
  • Thanks a lot for your effort, but I got the solution. If interested, posted it below. – İsmet Alkan May 18 '12 at 12:48