imageJ how to get pixel rgb value?

David picture David · Apr 22, 2013 · Viewed 7.8k times · Source

i have a simple plugin which saves the polygon coordinates:

Roi roi = imp.getRoi();
Polygon p = roi.getPolygon();
for (int i = 1; i <= p.npoints; i++) {
// létrehozzuk az onvif féle vector-t
org.onvif.ver10.schema.Vector myVector = new Vector();
myVector.setX((float) p.xpoints[i - 1]);
myVector.setY((float) p.ypoints[i - 1]);
op.getPoint().add(myVector);
// IJ.log("Vector X Elements " + i + " :" + MyVector.getX());

        }

but i want to get the coordinates rgb values like this: enter image description here

can you help me with this? Thank you!

Answer

Josef Borkovec picture Josef Borkovec · Apr 22, 2013

Supposing the image is 32-bit RGB:

ImagePlus im = IJ.getImage();
ImageProcessor imp = im.getProcessor();

int[] rgb = new int[3];
imp.getPixel(X,Y,rgb);

IJ.log(Arrays.toString(rgb));