Find Edges with ImageJ Programmatically
Asked Answered
P

2

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.

Protectionist answered 18/5, 2012 at 12:23 Comment(1)
See also this related Q&A.Riccio
P
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();
Protectionist answered 18/5, 2012 at 12:46 Comment(2)
If you do this, you can declare ip as ImageProcessor like you did in your questionTrattoria
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.Blinni
T
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();
Trattoria answered 18/5, 2012 at 12:32 Comment(3)
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.Blinni
I am no ImageJ expert, but looking at the documentation 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.Trattoria
Thanks a lot for your effort, but I got the solution. If interested, posted it below.Blinni

© 2022 - 2024 — McMap. All rights reserved.