Hey,
I found the following plugin that adds up pixels with a specific gray value. My question is how can i color those pixels? I know the basics of Java but i cant find a method for this. /* This plugin counts pixels in a 8-bit or 16-bit image (Stack) in the defined interval. Author: M. Austenfeld */ import java.awt.*; import ij.plugin.*; import ij.*; import ij.gui.*; import ij.process.*; import ij.measure.ResultsTable; import ij.gui.GenericDialog; public class Count_Stack_Pixels implements PlugIn { public int pixelCount = 0;// The variable for the pixel count! public int min = 0;// The min value for the pixel count! public int max = 0;// The max value for the pixel count! public void run(String arg) { ImagePlus imp = WindowManager.getCurrentImage(); if (imp != null) { /*We proof if the image is an 8-bit or 16-bit image!*/ ImageProcessor im= imp.getProcessor() ; if (im instanceof ShortProcessor||im instanceof ByteProcessor ) { /*We create a dialog!*/ GenericDialog gd = new GenericDialog("Count Pixels"); gd.addNumericField("Min: ", min, 0); gd.addNumericField("Max: ", max, 0); gd.showDialog(); if (gd.wasCanceled()) return; /*We get the values from the dialog!*/ min = (int) gd.getNextNumber(); max = (int) gd.getNextNumber(); /*We create a results table!*/ ResultsTable rt = ResultsTable.getResultsTable(); rt.reset(); /*Get the active image !*/ /*We get the stack!*/ ImageStack stack = imp.getStack(); /*We loop through all stack images!*/ for (int n = 1; n <= stack.getSize(); n++) { /*Get the image processor of the image !*/ ImageProcessor ip = stack.getProcessor(n); int w = ip.getWidth(); int h = ip.getHeight(); /*We loop through all pixels in a stack image!*/ for (int v = 0; v < h; v++) { for (int u = 0; u < w; u++) { /*Get the pixel value!*/ int i = ip.getPixel(u, v); /*All values which match the interval are counted!*/ if (i >= min && i <= max) { pixelCount++; } } } rt.incrementCounter(); /*We add the counted values to the results table!*/ rt.addValue("Count", pixelCount); pixelCount = 0; }//end of the stack! rt.show("Results"); } else { IJ.showMessage("Requires an 8-bit or 16-bit image !"); } } else { IJ.showMessage("No image opened !"); } } } |
Free forum by Nabble | Edit this page |