I want to analyse images using the ImageJ framework in java. How can I open an image? I need to have an ImageProcessor
object to be able to generate a histogram. Here is the code I have so far:
public void run(ImageProcessor ip) {
int[] H = new int[256]; // histogram array
int w = ip.getWidth();
int h = ip.getHeight();
for (int v = 0; v < h; v++) {
for (int u = 0; u < w; u++) {
int i = ip.getPixel(u, v);
H[i] = H[i] + 1;
}
}
// ... histogram H[] can now be used
}
I work with medical grayscale images where a ColorProcesser is not appropriate. In that case I use
Opener opener = new Opener();
String imageFilePath = "somePath";
ImagePlus imp = opener.openImage(imageFilePath);
ImageProcesser ip = imp.getProcessor(); // ImageProcessor from ImagePlus