Hi all, I am having some problem writing an ImageJ plugin for display image histogram.
import ij.ImagePlus;
import ij.plugin.filter.PlugInFilter;
import ij.process.ByteProcessor;
import ij.process.ImageProcessor;
public class Create_New_Image implements PlugInFilter {
String title = null;
public int setup(String arg, ImagePlus im) {
title = im.getTitle();
return DOES_8G + NO_CHANGES;
}
public void run(ImageProcessor ip) {
int[] hist = ip.getHistogram();
int w = 256;
int h = ???;
ImageProcessor histIp = new ByteProcessor(w, h);
histIp.setValue(255); // white = 255
histIp.fill();
for (int v = 0; v < h; v++) {
for (int u = 0; u < w; u++) {
ip.getPixel(u, v);
histIp.putPixel(u, v, 0);
}
}
// display histogram:
String hTitle = "Histogram of " + title;
ImagePlus histIm = new ImagePlus(hTitle, histIp);
histIm.show();
// histIm.updateAndDraw();
}
}
I don't know how to get the height of the histogram. I know it's actually the largest frequency in the histogram, but I don't know how to get it and equate to my variable h (line 17). And I'm not sure if line 24-27 is correct for drawing the histogram values as black bars.